我有以下角度:
angular.module("app.components", []);
angular.module("app", [
"app.components"
]);
angular.module("app.components")
.component('testWidget', {
templateUrl: '/Widgets/TestWidget/Templates/TestWidget.template.html',
bindings: {
something: "="
},
controller: function () {
var ctrl = this;
// ctrl has nothing on it
}
});
<div ng-app="app">
<test-widget something="Shoopy"></test-widget>
</div>
但something
不是控制器中对象(this
)的一部分。我错过了什么?
答案 0 :(得分:1)
双向绑定(期望父范围属性监视值更改):
bindings: {
something: "="
}
父控制器需要设置属性:
$scope.Shoopy = "hello world"
对于参数绑定,请使用以下命令:
字符串值绑定:
bindings: {
something: "@"
}
答案 1 :(得分:0)
您忘了controllerAs
,因为您使用的是this
而不是$scope
试试这个
angular.module("app.components")
.component('testWidget', {
templateUrl: '/Widgets/TestWidget/Templates/TestWidget.template.html',
bindings: {
something: "="
},
controllerAs: "ctrl",
controller: function () {
var ctrl = this;
// ctrl has nothing on it
}
});