コントローラーからデータを取得するカスタムディレクティブを作成しました。
私の変数はスコープ要素内に表示されますが、それにアクセスしようとすると、 未定義
HTML
<map borders="vm.borders"></map>
指令
angular.module("myApp.directives")
.directive("map", [ function() {
return {
restrict: "E",
scope: {
borders: "="
},
link: function(scope, element, attrs) {
console.log(scope); //cfr linked image
console.log(scope.borders) //undefined
}
}
}]);
これがスコープです。境界変数が含まれています。
この境界値を取得するために何が欠けていますか?
回答:
回答№1の場合は3追加することを提案できます ng-if
ディレクティブに、たとえば vm.borders
約束から得られる ng-if
必要とされている:
<map borders="vm.borders" ng-if="vm.borders"></map>