I have this code where I am expecting some data from the View/HTML but the variable $scope.cityName is undefined.
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);
});
Here is the 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.resultdata correct in your console ?