angularjs--控制器的显示与隐示使用
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>13-angularjs--控制器的显示与隐示使用</title> <script src="../js/angularjs.js"></script> <script src="../js/index13.js"></script> </head> <body> <!-- angularjs的数据绑定,双向绑定,M,V,c之间的绑定 --> <div ng-app="myApp"> <div ng-controller= "firstController"> <input type="text" ng-model="Data.message" value="" /> firstData--{{Data.message}} </div> <div ng-controller="secondController"> <input type="text" value="" /> secondData--{{Data.message}} </div> </div> </div> </body> </html>
var myApp = angular.module("myApp",[]); myApp.factory('Data', function(){ return {message:'小平果'}; }); myApp.factory('Service', ['$windows', function(a){ console.log(a); }]) // 1、隐示的依赖注入 myApp.controller('firstController', function($scope,Data){ $scope.Data = Data; }); // 2、显示的依赖注入 myApp.controller('secondController', ['$scope','Data', function(a,b){ a.Data = b; console.log(a,b); }]);