1、問題背景
AngularJS特有的一個依賴注入,當在一個物件創建時,需要依賴另一個物件。
2、實現源碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS之依赖注入(实例一)</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <style> body,html{ font-family: "微软雅黑"; font-size: 12px; font-feature-settings: on; } .showContent{ width: 200px; padding: 10px; margin: 10px; border: 1px dashed #2AABD2; } </style> <script> var app = angular.module("reApp",[]); app.config(function($controllerProvider){ $controllerProvider.register("reCon",["$scope",function($scope){ $scope.content = ""; $scope.clickShow = function(){ $scope.content = "showContent"; $scope.showContent = "依赖注入"; }; }]); }); </script> </head> <body ng-app="reApp"> <p ng-controller="reCon"> <button type="button" ng-click="clickShow();">依赖注入</button><br><br> <label class="{{content}}">{{showContent}}</label> </p> </body> </html>
3、實現結果
rrreee
(2)點擊按鈕時
以上就是AngularJS之依賴注入(實例一)的內容,更多相關內容請關注PHPcn中文)!