AngularJs $scope undefined when controllers are inside a module

前端 未结 4 1754
清酒与你
清酒与你 2021-01-30 20:44

I\'m trying to use the angular-seed template with the default settings. In controllers.js I use

angular.module(\'myApp.controllers\', []).
  control         


        
4条回答
  •  旧巷少年郎
    2021-01-30 21:11

    I was also searching for that one, it seems that you need to type '$scope' before the function, as below:

        angular.module('myApp.controllers', []).
      controller('MyCtrl1', ['$scope', function($scope) {
          $scope.test = 'scope found!';
      }])
      .controller('MyCtrl2', ['$scope',function() {
    
      }]);
    

    It kinda makes sense, I think it should be more clear though..

提交回复
热议问题