【发布时间】:2014-12-14 06:18:01
【问题描述】:
我似乎无法思考如何实现这一目标。我有一个如下所示的指令:
.directive('seqWidget', ['Sequence', function(Sequence){
return {
restrict: 'E',
scope: {
placeholder: '@',
option: '@'
},
template: '<fieldset><legend data-ng-transclude></legend><input type="text" placeholder = {{placeholder}} autofocus data-ng-model="index" data-ng-change="retrieve({{option}});"/>{{output}}</fieldset>',
replace: true,
transclude: true,
link: function ($scope, $elem, $attr){
$scope.retrieve = function(key){
//var option = $attr.option;
console.log(key);
}
}
}
}]);
我的 HTML 是这样的:
<seq-widget placeholder="Index 0-400" option="accurate">Which index number would you like to gain accuracy on?</seq-widget>
我已经尝试了其他几种方法来实现基于属性值更改函数调用的动态方法。我会使用 '&' 前缀,但我希望在输入更改时触发此功能。有没有一种实用的方法来实现我想要做的事情?或者我需要使用 jQuery 来表达类似 $('input').on('change', function(){}); 的内容吗?在我的链接功能中?
【问题讨论】:
标签: javascript html angularjs angularjs-directive angularjs-scope