通过路由器的局部变量
Local variable through router
我的主要组件有一个后退按钮,该按钮并不总是可见(取决于 child 组件)。如何让它工作?我尝试使用局部变量,但没有成功。
在我的 app.component.html (parent) 中,我有以下内容
<button *ngIf="child.goBackUrl">Back</button>
<router-outlet #child></router-outlet>
在 ChildComponent 我有
goBackUrl: string = "test";
这行不通。我需要一种方法,可以从 parent 组件访问 child 变量和方法。如果我尝试从 child 组件内的 parent 调用方法,我会得到
ORIGINAL EXCEPTION: TypeError: self._el_102.goBack is not a function
有什么想法吗?我尝试了一些不同的东西,但没有成功
Angular2 数据绑定仅适用于静态添加到组件模板的组件和指令(仅限父子)。
对于所有其他情况,请使用 https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
中演示的共享服务
我的主要组件有一个后退按钮,该按钮并不总是可见(取决于 child 组件)。如何让它工作?我尝试使用局部变量,但没有成功。
在我的 app.component.html (parent) 中,我有以下内容
<button *ngIf="child.goBackUrl">Back</button>
<router-outlet #child></router-outlet>
在 ChildComponent 我有
goBackUrl: string = "test";
这行不通。我需要一种方法,可以从 parent 组件访问 child 变量和方法。如果我尝试从 child 组件内的 parent 调用方法,我会得到
ORIGINAL EXCEPTION: TypeError: self._el_102.goBack is not a function
有什么想法吗?我尝试了一些不同的东西,但没有成功
Angular2 数据绑定仅适用于静态添加到组件模板的组件和指令(仅限父子)。
对于所有其他情况,请使用 https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
中演示的共享服务