【发布时间】:2017-06-04 23:25:38
【问题描述】:
我正在尝试将一些值绑定到控制器代码应该可用的 angular 1.6 组件中。
我一定是误会了,但是控制器运行时变量不可用。我管理它的唯一方法是通过 $timeout 将代码推送到下一个摘要周期。
我在这里做错了什么?
相关部分在这里:
var SelectorCtrl = ['$scope', '$http', '$timeout',
function ($scope, $http, $timeout) {
var self = this;
alert("1: " + self.hierarchyId);
// I'm not 100% sure why this has to be in the next digest cycle
$timeout(function(){
$scope.categories = self.categories;
alert("2: " + self.hierarchyId);
});
}
app.component('categorySelector', {
templateUrl: 'categorySelector.html',
controller: SelectorCtrl,
bindings: {
hierarchyId: "@",
disabled: "=",
categories: "=",
onSelectionChanged: "&"
}
});
请参阅 plunker:https://plnkr.co/edit/8rtDuCawdHaiXzQU5VBR
【问题讨论】:
-
你为什么在同一个组件中混合
$scope和this?
标签: angularjs