angular.module('app',[]) .controller('validateboxCtr', function($scope, $element) { $scope.name = ''; $scope.email = ''; $scope.birthday = ''; $scope.url = ''; $scope.phone = ''; $scope.data = { 'Name':$scope.name, 'Email':$scope.email, 'Birthday':$scope.birthday, 'URL':$scope.url, 'Phone':$scope.phone }; $scope.$watch('data',function(value){ console.log(value); }); // console.log($scope) });
代码如上,ng-model 绑定了5个值,想全部放入data变量中,但是data变量却无法双向绑定了,求解决
为什么不直接 ng-model = "data.name" ....
不要ng-model="name"啊
自动data变化,scope双向的啊,不是吗?