我有这个代码,我期待从视图/ HTML的一些数据,但变量$ scope.cityName是未定义的。
app.controller("citycontroller", function ($scope, cityfactory) {
$scope.searchByCid = function() {
console.log("Checking for city data");
var promise = cityfactory.serverCall($scope.cityName);
promise.then(function (data) {
$scope.result = data.data;
console.log($scope.result);
}, function (error) {
$scope.error = error;
});
};
console.log($scope.cityName);
});
下面是HTML
<div>
<input type="text" ng-model="cityName" placeholder="Search places.." ng-init="cityName='Delhi'">
<button ng-click="searchByCid()" id="checkcity">Check</button>
</div>
是'$ scope.result'数据在您的控制台中正确吗? –