Following up from AngularJS : Why my watch is not working
function myController($scope, $http) {
$scope.abc = abcValueFromOutsideOfMyController;
$scope.getAbcCnt= function()
{
url2 = baseURL + '/count/' + $scope.abc;
$http.get(url2).success(function (data) {
$scope.abcCnt = data.trim();
});
};
$scope.$watch('abc',getAbcCnt);
}
Why I get undefined error on $scope.abc.
abcValueFromOutsideOfMyController is set by selecting element through a drop down. It will be undefined initially but as soon as dropdown is selected, the value will be something other than undefined, I verified in console, I get some value.
Drop down code is here
$(document).on('click', '.dropdown-menu li a', function () {
selectedItem = $(this).text();
$("#selectedItem").text(selectedItem);
abcValueFromOutsideOfMyController= selectedItem.trim();
console.log(abcValueFromOutsideOfMyController);
});
Here is my html
<div class="dropdown btn">
<div id="collectiondropDown" class="dropdown-toggle" id="dLabel" role="button" data-toggle="dropdown"
data-target="#" >
<span id="selectedItem" ng-model="abc">Items</span>
<b class="caret"></b>
</div>
<ul id="dropDownUL" class="dropdown-menu pull-left" role="menu" aria-labelledby="dLabel">
</ul>
</div>
I am new to AngularJS, let me know if there is some fundamental concept I am missing and above is not possible to do.