为什么会这样?
<input type="text" ng-model="address"/>
app.controller("MainCtrl", ['$scope', function($scope){
$scope.location = {address: $scope.address};
$scope.getFood = function(){
console.log($scope.location);
console.log($scope.address)
};
记录$ scope.location给出
Object {address: undefined}
当我记录$ scope.address时,它会给我值。
答案 0 :(得分:1)
您可以设置$scope.location = {address: null};
然后添加标记<input type="text" ng-model="location.address"/>