Why is my Angular controller undefined?

后端 未结 3 1720
执念已碎
执念已碎 2020-12-21 10:22

I\'ve been following a tutorial, the textbook assures me that this works, but it\'s bombing with

Error: [ng:areq] Argument \'SimpleController\' is not

3条回答
  •  失恋的感觉
    2020-12-21 10:44

    You need to create an app and register it to that app like so:

    var myApp = angular.module('myApp',[]);
    
    myApp.controller('SimpleController', ['$scope', function($scope) {
      $scope.customers = [
                {name: 'John Smith', city: 'Phoenix'},
                {name: 'Jane Smith', city: 'Pittsburgh'},
                {name: 'John Doe', city: 'New York'},
                {name: 'Jane Doe', city: 'Los Angeles'}
            ];
    }]);
    

    and in your html:

    
    

    Full example in a plunker: http://plnkr.co/edit/tBwjJU3tc6tVc599RVFR?p=preview

提交回复
热议问题