sharing data between controllers
可以通过factory(0服务来分享数据
<!DOCTYPE html > <html ng-app="demo"> <head> <title></title> <script src="angular.min.js" type="text/javascript"></script> </head> <body> <div ng-controller="firstCtl"> <input type="text" ng-model="data.message" /> <h1>{{data.message}}</h1> </div> <div ng-controller="secondCtl"> <input type="text" ng-model="data.message" /> <h1>{{data.message}}</h1> </div> </body> <script> var demo = angular.module("demo", []); demo.factory("dataServices", function () { return {message:"Jackey"}; }); demo.controller("firstCtl", function ($scope, dataServices) { $scope.data = dataServices; }); demo.controller("secondCtl", function ($scope, dataServices) { $scope.data = dataServices; }); </script> </html>