I am encountering an issue with this code where the variable $scope.cityName is coming up as undefined, even though I am expecting data from the View/HTML.
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);
});
This is the corresponding HTML code snippet:
<div>
<input type="text" ng-model="cityName" placeholder="Search places.." ng-init="cityName='Delhi'">
<button ng-click="searchByCid()" id="checkcity">Check</button>
</div>