angular - How to pass Attribute as dependency in provide function? -


i building simple login verification directive, work described here. make adjustments - create new provider in boot function this:

new provider(routeroutlet, {     usefactory: (_elementref: elementref, _loader:dynamiccomponentloader, _parentrouter: router,_authenticationservice:authenticationservice) => new sessionverificationrouteroutlet(_elementref, _loader, _parentrouter, _authenticationservice),     deps: [elementref, dynamiccomponentloader, router, authenticationservice] }) 

however, can see here:

@directive({     selector: 'auth-router-outlet' }) export class sessionverificationrouteroutlet extends routeroutlet {     publicroutes: string[];     private parentrouter: router;       constructor(         _elementref: elementref, _loader: dynamiccomponentloader,         _parentrouter: router, @attribute('name') nameattr: string,  private _authenticationservice: authenticationservice     ) {         super(_elementref, _loader, _parentrouter, nameattr);          this.parentrouter = _parentrouter;         this._authenticationservice = _authenticationservice;         this.publicroutes = [             'login'         ];     }      activate(instruction: componentinstruction) {         if (this._canactivate(instruction.urlpath)) {             return super.activate(instruction);         }          this.parentrouter.navigate(['login']);     }      _canactivate(url) {         return this.publicroutes.indexof(url) !== -1 || this._authenticationservice.isloggedin()     } } 

as can see, 'sessionverificationrouteroutlet' take @attribute element in constructor. how can pass required attribute in new provider(..) method?

@attribute value constant attribute of element (in case, name one) directive applies on. somethinhg that:

<auth-router-outlet name="something"></auth-router-outlet> 

there no need define when create provider... don't think need use usefactory configure custom router outlet. following enough:

provide(routeroutlet, {   useclass: sessionverificationrouteroutlet }) 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -