I have the below HTML on a page:
Angula
No real need for $rootScope
. Create a parent controller (e.g. RootController
) with a function on its scope. The child scopes will automatically inherit it:
...
function RootController($scope) {
$scope.item = {};
$scope.setBasketCount = function (detail) {
$scope.item.basketCount = detail.getCount();
}
}
In your detail controller you just use the setBasketCount()
function:
function DetailController($scope, item, basketDetail) {
$scope.item = item;
$scope.setBasketCount(basketDetail);
//more code
}