角度 js 参数 'DemoCtrl' 不是

angular js Argument 'DemoCtrl' is not a

本文关键字:不是 DemoCtrl js 参数 角度      更新时间:2023-09-26

注册.html

<div ng-controller="DemoCtrl" layout="column" ng-cloak="" class="md-inline-form inputdemoBasicUsage" ng-app="inputBasicDemo">
  <md-content md-theme="docs-dark" layout-gt-sm="row" layout-padding="">
    <div>
      <md-input-container>
        <label>Title</label>
        <input ng-model="user.title">
      </md-input-container>
</div>

应用.js

var myApp = angular.module('myApp', [
  'ngRoute',
  'artistControllers'
]);
myApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
  when('/signup', {
        templateUrl: 'partials/signup.html',
        controller: 'DemoCtrl'
 }).  otherwise({
    redirectTo: '/signup'
  });
}]);

控制器.js

angular
.module('inputBasicDemo', ['ngMaterial', 'ngMessages'])
.controller('DemoCtrl', ['$scope', '$http',function($scope) {
  $scope.user = {
    title: 'Developer',
    email: 'ipsum@lorem.com',
    firstName: '',
    lastName: '',
    company: 'Google',
    address: '1600 Amphitheatre Pkwy',
    city: 'Mountain View',
    state: 'CA',
    biography: 'Loves kittens, snowboarding, and can type at 130 WPM.'n'nAnd rumor has it she bouldered up Castle Craig!',
    postalCode: '94043'
  };
  $scope.states = ('AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS ' +
  'MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI ' +
  'WY').split(' ').map(function(state) {
      return {abbrev: state};
    })
}])

收到 http://errors.angularjs.org/1.2.9/ng/areq?p0=DemoCtrl&p1=not%20aNaNunction%2C%20got%20undefined 错误。

在通过应用程序路由请求时.js 和控制器面临此问题,但是在采用代码形式 https://material.angularjs.org/latest/demo/input 代码时,代码不会抛出错误。

请建议

您正在减少要注入控制器的两件事,但只使用 $scope 。同时添加$http服务

.controller('DemoCtrl', ['$scope', '$http', function($scope, $http) {

已更新

您的模块名称在app.jscontroller.js之间是不同的。

您也不应该在多个位置设置模块的注入。

建议:

应用.js

var myApp = angular.module('myApp', [
  'ngRoute',
  'artistControllers',
  'ngMaterial',
  'ngMessages'
]);

控制器.js

angular
.module('myApp')
.controller('DemoCtrl', ['$scope',function($scope) {
// code ommitted
});

源语言

app.jscontroller.js之间的模块名称不同,因此DemoCtrl不适用于myApp模块。