For example, assigning an object cannot be two-way bound, but assigning a string or something can be monitored. What if I have to assign a value to an object so that it can be bound in two directions (I said that the value assigned after clicking the button cannot be bound)
<body ng-app="app">
<p ng-controller="loginCtrl">
<pre>{{info}}</pre>
<button ng-click="setvalue()">aaaa</button>
</p>
<p ng-controller="loginCtrl">{{info.isIn}}</p>
<script type="text/javascript">
var app = angular.module('app', []);
app.factory('login', ['$timeout', function($timeout){
var ret = {}
ret.info = {
isIn:false
}
//如果这里赋值成这样
var dd = {
isIn:'aaaaa'
}
$timeout(function() {
ret.info.isIn = true;
}, 1000);
ret.setvalue = function(){
//这里的修改就无法绑定,这事为什么
ret.info = dd
//ret.info.isIn=dd.Isin //这样写就可以
}
return ret;
}]);
app.controller('loginCtrl', ['$scope', 'login', function($scope, login){
$scope.info = login.info;
$scope.setvalue = function(){
login.setvalue('dddd')
}
}])
</script>
</body>
Because the data on the server is a jsonp object, there are many passed down.
Please help me~~, the above code can be run by importing angular, please help me correct it
This involves basic knowledge of js and has nothing to do with angular. Simple example: