New to Angular, so forgive me, but I have this as my index.html:
<body>
<div data-ng-controller="storeList">
<select ng-model="selectedItem" ng-options="c.CustomerID as c.CustomerName for c in customers"
ng-change="changeCust(selectedItem)">
<option value="">Select Store</option>
</select>
</div>
<div data-ng-controller="storeInfo">
Selected Store is: {{selectedStore}}
</div>
</body>
and this for my js:
var storeApp = angular.module('storeApp',[])
storeApp.factory('currentCustomer',function($http) {
return {
customerID :0,
getCustomers: function () {
console.log("in get")
return [{CustomerID:1,CustomerName:'Store 1'},
{CustomerID:2,CustomerName:'Store 2'},
{CustomerID:3,CustomerName:'Store 3'}]
}
}
});
storeApp.controller('storeList',function($scope,$http,currentCustomer) {
$scope.customers = currentCustomer.getCustomers()
$scope.changeCust = function changeCust(id) {
console.log("Changing ID from: "+ currentCustomer.customerID)
currentCustomer.customerID = id
console.log("ID Is now: " + currentCustomer.customerID)
}
});
storeApp.controller('storeInfo',function($scope,currentCustomer) {
console.log("Setting up storeInfo")
$scope.man = 'Rob';
$scope.selectedStore = currentCustomer.customerID;
});
When I change the select, the currentCustomer.customerID changes but does not update in the storeInfo controller.
What am I missing.
Thanks for your help.