0
我app.component
这样的:路由器+变化而变化[Angularjs 2]
import { Component, Input } from '@angular/core';
import {AuthTokenService} from './auth-token.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(
private Auth: AuthTokenService) { };
isGuest: any = this.Auth.canActivate();
title = 'app works!';
}
,我需要从子组件改变isGuest
VAR login.component
在app.component.html
我有这样的:
<h1>
{{isGuest}}
</h1>
<router-outlet></router-outlet>
我试着用@Output and Emitter
改变它,但它不工作,因为我是我们成角度路由器。
'isGuest:任何= this.Auth.canActivate();'这是不正确的行。除此之外,您可以使用服务从childcmp对parentcmp进行更改。 – micronyks
为什么这是不正确的?你应该怎么样才能向我展示一个例子? –
'constructor( private Auth:AuthTokenService){this.isGuest = Auth.canActivate();}'OR'ngOnInit(){ this.isGuest = this.Auth.canActivate();}' – micronyks