如何将范围模型的引用传递给函数

这个问题在这里已经有了答案:

  • Javascript的参考与价值[复制] 4个答案

  • 改变你的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

    上一篇: How to pass a reference of scope's model to a function

    下一篇: JavaScript array assign issue