How to pass a reference of scope's model to a function, where I can edit the contents of it?
For example, I have controller like this:
app.controller('MyController', function ($scope) {
$scope.magic = 123;
$scope.someMethod = function(model) {
model = 321;
}
});
And a view:
<div data-ng-controller="MyController as ctrl">
...
<input type="text" data-ng-model="magic">
<button type="button" data-ng-click="someMethod(magic)">
</div>
Now when I click the button, it almost works, but after someMethod
, the actual $scope.magic has not changed, it's still 321. So apparently someMethod
creates a copy of the model, not reference. How to get the reference instead?