0
我想通過共享服務在應用組件中顯示和隱藏我的導航。 當組件_service.Login調用this._service.setLogin(),屬性將被設置爲true,但不會影響到應用程序組件,並結合不行從其他子組件綁定應用組件屬性
這是我的應用程序組件
@Component({
selector: 'pm-app',
templateUrl: "/app/app.component.html",providers:AuthenticationService]
,providers: [AuthenticationService]
})
constructor(private _service: AuthenticationService) {}
<nav class="off-canvas-navigation">
<li *ngIf='!_service.Login'><a [routerLink]="['/login']">login</a></li>
<li *ngIf='_service.Login'><a [routerLink]="['/logout']">logOut</a></li>
</nav>
<div id="page-content">
<router-outlet></router-outlet>
</div>
</nav>
和我的共享共用服務隊是波紋管
@Injectable()
export class AuthenticationService {
Login: boolean;
setLogin(){this.login=true;}
和我的另一組成部分是在這裏
@Component({
templateUrl: "app/home/login-form.component.html",
providers: [AuthenticationService]
})
export class LoginFormComponent implements OnInit {
constructor(private _service: AuthenticationService) {}
login() {this._service.setLogin();}
}
組件裝飾器中的'providers'?這是哪個角度2版本? – choz
我設置了提供者。角2 rc5 –