コントローラコードで使用できる角度1.6のコンポーネントにいくつかの値をバインドしようとしています。なぜバインディング値はすぐにコントローラで使用できないのですか
私は誤解する必要がありますが、コントローラーを実行するときに変数を使用することはできません。私がそれを管理した唯一の方法は、次のダイジェストサイクルにコードをプッシュするために$タイムアウトを入れることです。
私はここで間違っていますか?
関連するセクションはここにある:
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'を混合していますか? – Claies