自定义了一个指令,想在一个页面中多次使用,每个指令传入的参数不同,如何让他获取对应参数取得的值
html
<select-option title="性别" grup="sex" ></select-option>
<select-option title="血型" grup="blood" ></select-option>
js
app.directive('selectOption',function($http){
return{
restrict:'E',
scope :'' ,
link:function(scope, element, attrs) {
scope.title = attrs.title;
scope.grup = attrs.grup;
scope.list = attrs.grup;
var data = {
'groupName':attrs.title
};
scope.ceshi = function(a){
alert(a);
}
$http.post('/datadicItem/findItemsByGroupName',data,postCfg)
.success(function(resp){
// debugger
scope.list = resp;
console.log(scope.list);
});
},
template:'<div style="text-align:center;height:30px;">'+
'<span class="r" style="margin-top:4px;width:120px;"> '+
'<span style="vertical-align: 12px;"> {{title}}'+
'<select style="margin-left:5px;"'+
'ng-model="grup"'+
'ng-change="ceshi(grup)"'+
'ng-options="act.id as act.itemname for act in list">'+'<option value="">'+'--请选择--'+'</option>'+
'</select>'+
'</span>'+
'</span>'+
'</div>',
replace:true,
};
});
option选项里的具体内容 如果是经常变的 要向后端发起请求获取 如果是性别只有男女这种 就可以写在controller里面