私には、scope
と宣言されたディレクティブが含まれているコード(鉱山ではない)があります。私の願いは、他の場所でディレクティブを使用し、テンプレート内で使用される追加の変数を渡すことです。変数を指令に渡してDRY?
私が渡したい変数はtheVar
です。
私は仕事ができることが分かった唯一の解決策は悪夢になります
(function(angular) {
'use strict';
angular.module('theFoo', [])
.controller('Controller', ['$scope', function($scope) {
$scope.theVar = true;
}])
.directive('aDirective', function() {
return {
scope: {
'someVarThatWasHereBefore': '=',
'theVar': '='
},
template: '<p ng-show="theVar">You have successfully passed a boolean value!</p>'
};
});
})(window.angular);
<body ng-app="theFoo">
<div ng-controller="Controller">
<a-directive data-the-var="theVar"></a-directive>
</div>
</body>
scope
内の私の変数4回の名前を繰り返すことなく、それを行うにはどのような方法がありますとHTML要素?
あなたは、私はそのディレクティブは、より高いレベルの機能の種類と 'scope'として働き理解(ディレクティブのオブジェクトリテラルの定義を返す)関数を返す関数 –