Skip to content Skip to sidebar Skip to footer

How To Override Component In Angularjs

I want to override one of existing component in my custom module. Here is the component - import {SeComponent, TypedMap} from 'smarteditcommons'; import { GenericEditorField, Gener

Solution 1:

If you want your Component two have a different behaviour in another Module, the right way is to inject a Service with a different value to that Module. Then read the value from component and decide what to do.

In your service:

@Injectable()
exportclassMyService {
 type;

 constructor(type){
  this.type = type;
 }
}

In your module (each module a differnt value in constructor):

  providers: [
    { provide: MyService , useValue: new MyService(1)},

And finaly in your component:

contructor(private service: MyService){
 if(service.type == 1){
  // do a different thing
 }
}

Post a Comment for "How To Override Component In Angularjs"