假设我有这样的指令
Save
现在我想要做的是点击按钮获取输入元素的值,我该怎么做。
我只是用这个逻辑来理解指令中范围和事件处理的工作。谢谢
答案 0 :(得分:0)
模板中作为模型指定的值可作为Controller
和link
函数
app.directive('tablesClick', function () {
return {
restrict: 'E',
template: [
'<table>',
'<tr>',
'<td> <label>This is local value: {{btnval}}</label><br/><input ng-model="btnval" type="text" /><button type="button" ng-click="func()" >reverse</button>',
'</tr>',
'</table> '
].join(''),
scope: {
btnval: '='
},
controller: function ($scope, $element) {
$scope.func = function () {
console.log($scope.btnval); // this is the desired value
};
},
link: function (scope, element, attrs) {
}
}
});