AngularJS (5) ng-controller 批次宣告
如果你想要在一個app內快速定義多個控制器,好比說印出不同的歡迎字串,你可以試看看批次的相依注入宣告。
ng-controller 批次的相依注入宣告
<head> <script> var app1 = angular.module("app1",[]); app1.controller({ "HelloController": ['$scope', function($scope){ $scope.words = "Hello! I'm Lily."; }], "HelloController2": ['$scope', function($scope){ $scope.words = "GoodBye. See you tomorrow."; }] }); </script> </head>
<body ng-app="app1"> <div ng-controller="HelloController"> {{words}} </div> <div ng-controller="GoodByeController"> {{words}} </div> </body>
{{words}}
{{words}}
如果你只想要簡單定義一個控制器,可以參考看看我的前一篇AngularJS (4) ng-controller宣告。
留言
張貼留言