我有這個代碼,我期待從視圖/ 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'數據在您的控制檯中正確嗎? –