<!DOCTYPE html> <html ng-app="demo"> <head> <title></title> </head> <body> <input type="text" ng-model="data.message" /> <h1>{{data.message}}</h1> <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 src="angular.min.js" type="text/javascript"></script> <script> var demo = angular.module("demo", []); demo.controller("firstCtl", function ($scope) { $scope.data = {message:"JACKEY"}; }); demo.controller("secondCtl", function ($scope) { $scope.data = { message: "cSSI" }; }); </script> </html>
这个例子给我的认识是:
没有声明在controller里面的全局message会对声明在controller里面的message产生影响,
firstCtl不对secondCtl产生影响