I'm new to Angular and trying to write some simple app. I have problem using ngSwitch to switch the according directive on demand as follow.
the html markups :
main html file: directiveOne:
.directive('directiveOne',function(){
return {
restrict:"AE",
replace:true,
template:"<div>this is directive one</div>",
controller:"Dir1Controller",
}
})
.directive('directiveTwo',function(){
return {
restrict:"AE",
template:"<div>this is directive 2</div>,
controller:"Dir2Controller"
}
})
and a service to share data between controller.
.factory('ShareDataFct',function($rootScope){
var srv={};
srv.setValue=function(value){
this.srv.var = value;
$rootScope.$broadcast('varChanged');
}
return srv;
})
and finally, the 3 controllers for directives.
.controller('MainController',function($scope,ShareDataFct){
$scope.$watch('varChanged',function(){
$scope.myvar=ShareDataFct.var;
})
})
.controller('Dir1Controller',function($scope){
//nothing to do here yet
})
.controller('Dir2Controller',function($scope){
//nothing to do here yet
})
and then I try to change the ShareDataFct var but the view (ng-switch) does not change to show the directives according to the myvar change. Please advise. Thank you.