<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <title></title></Head><BodyNg-app= "MYAPP"> <DivNg-controller= "C1">{{Name}}, {{msg}}, {{datas} }</Div> <DivNg-controller= "C2">{{Name}}, {{msg}}, {{datas} }</Div></Body><Scriptsrc= "Angular.js"></Script><Script> varapp=Angular.module ("myApp",[]); //the biggest difference between factory and service is that the type that the service injects must be an object and factory can be any typeApp.factory ('custData1',function(){ return{message:"Share your data! ", data:['a','b','C'] } }); App.controller ("C1", function($scope, custData1) {$scope. Name="123"; $scope. MSG=Custdata1.message; $scope. Datas=custdata1.data[1]; }); App.controller ("C2", function($scope, custData1) {$scope. Name="456"; $scope. MSG=Custdata1.message; $scope. Datas=custdata1.data[2]; });</Script></HTML>
Angularjs shared data between parallel controllers