无法将范围变量绑定到数组键?

时间:2014-07-27 05:05:04

标签: angularjs

为什么会这样?

<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时,它会给我值。

1 个答案:

答案 0 :(得分:1)

您可以设置$scope.location = {address: null};
然后添加标记<input type="text" ng-model="location.address"/>