【发布时间】:2023-03-05 17:03:01
【问题描述】:
我正在尝试查看子模块中的父属性。
我有这样的html。
<div ng-include="maincontainer.selected"></div>
在我的主容器中,我有这个:
class Maincontainer {
var:string;
scope: ng.IScope;
selected: String;
static $inject = ['$scope'];
constructor($scope: ng.IScope) {
this.scope = $scope;
this.var = 'init';
this.selected = "app/Views/ChildView.html";
}
}
我想在 ChildViewController 中查看 'var' 父属性。
class ChildView {
scope: ng.IScope;
static $inject = ['$scope'];
constructor($scope: ng.IScope) {
this.scope = $scope;
// Here I want to add a watch to the parent property.
}
}
谁能帮帮我?
【问题讨论】:
-
你试过
$watch$parent.var吗? -
问题是 typescript 无法识别 var 的名称并且无法转换
-
很抱歉,我不懂 TypeScript。但也许this 会有所帮助。
-
谢谢,但是这个链接并没有解决父作用域的问题,只针对自己作用域。
标签: javascript angularjs angularjs-scope typescript