如何将范围模型的引用传递给函数
这个问题在这里已经有了答案:
改变你的someMethod
为以下内容:
$scope.someMethod = function(model) {
model.magic = 321;
}
// Or accepting a new value
$scope.anotherMethod = function(model, value) {
model.magic = value;
}
HTML:
<input type="text" data-ng-model="model.magic">
<button type="button" data-ng-click="someMethod(model)">Do Some Magic!</button>
<!-- Or with passing a new value -->
<button type="button" data-ng-click="anotherMethod(model, '123')">Do Some Magic!</button>
的jsfiddle
链接地址: http://www.djcxy.com/p/20991.html