Angularjs ng change函数在加载数据之前在页面加载时运行?

Angularjs ng change函数在加载数据之前在页面加载时运行?,angularjs,angularjs-service,Angularjs,Angularjs Service,我的一个控制器函数在加载数据之前运行 html: <div ng-show="item.name"> <input ng-change="doChange()" ng-model="item.name"> </div> 我的服务: app.factory("MyService", function($http) { return { getData: function() { return $http.

我的一个控制器函数在加载数据之前运行

html:

<div ng-show="item.name">
    <input ng-change="doChange()" ng-model="item.name">
</div>
我的服务:

app.factory("MyService", function($http) {
    return {
        getData: function() {
            return $http.get("/data");
        }
    }
});
这导致

TypeError:无法读取未定义的属性“name”

因为doChange是在服务加载数据之前执行的。我不知道为什么会这样。doChange不应该仅在输入发生更改时运行,而应该在页面加载时运行。

更改

$scope.doChange() {
  $scope.item = $scope.other['test'].name
}


很抱歉,在代码的其他地方,我更改了item.name,这就是为什么在页面加载时启动它

我原以为ng模式在某种程度上触发了网络上的ng变化,但这只是我的愚蠢

$scope.doChange() {
  $scope.item = $scope.other['test'].name
}
$scope.doChange = function() {
  $scope.item = $scope.other['test'].name
}