首页 > angular自定义指令如何写

angular自定义指令如何写

现在我有这样三段类似的代码

<div ng-repeat="planStatuse in planStatuses" class="planlist">

       <input  type="radio" name="a" ng-value="planStatuse.id" ng-model="planStatus.status" ng-click="planStatusChange()">
       <span>{{planStatuse.name}}</span>

</div>

<div ng-repeat="_appType in appTypes" class="planlist appType">

                <input type="radio" ng-value="{{_appType.id}}" ng-model="appType.val" name="app">
                <span>{{_appType.name}}</span>

</div>

<div class="pageselect_s_list" ng-repeat=" centerPage in centerPages">

                <input type="radio"  name="center" ng-model="pageType" ng-value="centerPage.id" ng-click="changePage(pageType)">
                <span>{{centerPage.name}}</span>

</div>
我要把这三块代码写成一个自定义指令 ,但是以上代码有的有事件,有的没有事件,而且事件不一样,该如何写?

var eInput= angular.module("eInput", []);
eInput.directive('eInput',function(){

return {
    restrict: "A",
    template:' <div ng-repeat="inputList in inputListes track by $index" class="planlist">'+
   ' <input  type="radio" name="a" ng-value="inputList.id" ng-model="inputList.status" ng-click="planStatusChange($index)">'+
    '<span>{{inputList.name}}</span>'+
'</div>',
    replace:true,
    scope:{
        inputListes:'='
    }
}

});


你确认一下你每个要执行的函数是否都在controller作用域里

【热门文章】
【热门文章】