這是帶有應該在單擊時調用的函數的指令。ng-click在指令中不起作用
ebApp.directive('monthDir', function() {
return {
restrict: 'E',
templateUrl: 'htmlFiles/monthDirective.html',
transclude: true,
scope: {
ebObj: "=obj"
},
link: function link(scope, element, attrs, ngModelCtrl) {
scope.removeDir = function (removeVal) {
console.log("asd"); //not showing in the console
}
console.log(scope);
},
controller: function ($scope) {
}
}
})
下面的指令中的ng-click不起作用。該指令的HTML
<div class="row monthDirC">
<span class="glyphicon glyphicon-remove-sign pull-right cursorC"
ng-click="removeDir(ebObj.costArray[count])" ></span>
<div class="form-group">
<label for="datepick" class="col-md-6">Select month</label>
<md-datepicker id="datepick" class="col-md-6" ng-model="ebObj.costArray[count].myDate"
md-placeholder="Enter date"
md-min-date="minDate"
md-max-date="maxDate">
</md-datepicker>
</div>
使用該指令的HTML:
<div class="col-md-12">
<month-dir ng-transclude ng-repeat="count in ebObj.costArray[0].countArray" obj="ebObj.costArray[count+1]"></month-dir>
</div>
嘗試在除去功能名稱鏈接:功能鏈路(範圍,元件,ATTRS,ngModelCtrl){ - >鏈接:功能(範圍,元件,ATTRS,ngModelCtrl){ –
@WasifKhan。試過了。沒有工作。 – Abhi