I need to pass a variable to another controller. I have the following code which is related to the ListCtrl :
<a href="#items" data-router="article" ng-click="changeListName('metro')">
The link is going to another controller, ItemCtrl.
I want to pass a variable to the ItemCtrl. I thought of using a service called SharedProperties :
service('sharedProperties', function () {
var list_name = '';
return {
getListName: function() {
return list_name;
},
setListName: function(name) {
list_name = name;
}
};
});
When the link is clicked, I call an angular click event to trigger the following function :
$scope.changeListName = function(name) {
sharedProperties.setListName(name);
};
However, the ng-click does not seem to change the value of my shared property...
UPDATE
I put an alert inside the function triggered by ng-click and the alert is triggered, as it should be.
However, when I write my function like this :
$scope.changeListName = function(name) {
sharedProperties.setListName(name);
};
It doesn't work... it looks like 'sharedProperties.setListName(name);' is not executed...
If I put it outside the function with a dummy name (eg. metro), it works..
UPDATE 3
I tried multiple things and I am pretty confident that the problem is with this function :
$scope.changeListName = function(list_name) {
sharedProperties.setListName(list_name);
};
Do you have any idea why this is happening?