I have a very simple factory:
var tv3Services = angular.module('tv3Services',[]);
tv3Services.factory('PanelService', [function(){
var _panel = "";
return {
getPanel: function() {return _panel;},
changePanel: function(newPanel) {_panel = newPanel;}
};
}]);
And a controller which uses it:
var tv3App = angular.module('tv3App', ['tv3Services']);
tv3App.controller('AdminController', function($scope,PanelService) {
$scope.panel = PanelService.getPanel();
$scope.changePanel = function(panel) {
PanelService.changePanel(panel);
};
$scope.changePanel("hola");
});
And this simple markup:
<html ng-app="tv3App">
<head>
<script src="service.js"></script>
<script src="controller.js"></script>
</head>
<body ng-controller="AdminController">
<h1>This should send a glyphicon when panel ONLY is same as "start"</h1>
<div class="text-center">
<span ng-show="panel=='start'" class="glyphicon glyphicon-star"></span>
</div>
<strong>Panel is set to "hola" though ...</strong>
</body>
</html>
However, it's not working as it should at all. Panel seems not to be bound to anything. I'm calling $scope.changePanel("start");
so that should make trigger the service and assign it a value.
Why isn't this working?
I got a plunkr example.