在我的应用程序中,我将 html
模板嵌套在页面中。我需要对其他元素的 array
使用相同的模板。
并且指令
应该照常工作。 在我的例子中,link
方法没有被调用。
请任何人指导我正确的方法来解决这个问题。
这是我的 html :
<div class="content" ng-controller="main">
<span class="dgt" ng-repeat="digitDispaly in digitalArray"> //repating
<span class="sr">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
</span>
<span class="fl"></span>
</span>
<span class="line">Line</span>
</div>
js:
angular.module('myApp', [])
.controller("main", function($scope) {
$scope.digitalArray = ["3", "2", "7"];
});
angular.module("myApp")
.directive("digitDispaly", function () {
return {
restrict : "E",
link : function (scope, element, attrs) {
console.log("hi")
}
}
})
最佳答案
您也可以将其用作类,如下所示
http://plnkr.co/edit/eCCVW8obKdCNvKKGmd9S?p=preview
<span class="dgt digitDispaly " ng-repeat="digitDispaly in digitalArray"> //repating
angular.module("myApp")
.directive("digitDispaly", function () {
return {
restrict : "C",
link : function (scope, element, attrs) {
console.log("hi")
}
}
})
关于javascript - `ng-repeat` - `$scope` 数组长度的指令,保留 `html` 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30885717/