小编DDe*_*gro的帖子

名称为"PokemonCtrl"的控制器未注册

我正在尝试将控制器添加到我的Angularjs应用程序中.

这是我第一次在不使用$scope依赖项的情况下进行设置,并使用路由来声明我正在使用的控制器.

PokemonCtrl没有注册的地方,我做错了什么?另外,如果我在路由中声明控制器这意味着我不必在其他任何地方声明它?

app.js

    'use strict';

/**
 * @ngdoc overview
 * @name pokedexApp
 * @description
 * # pokedexApp
 *
 * Main module of the application.
 */
angular
    .module('pokedexApp', [
        'ngAnimate',
        'ngCookies',
        'ngResource',
        'ngRoute',
        'ngSanitize',
        'ngTouch'
    ])
    .config(function($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'views/main.html',
                controller: 'MainCtrl',
                controllerAs: 'main'
            })
            .when('/pokemon', {
                templateUrl: 'views/pokemon.html',
                controller: 'PokemonCtrl',
                controllerAs: 'controller'

            })
            .otherwise({
                redirectTo: '/main'
            });
    });
Run Code Online (Sandbox Code Playgroud)

pokemonCtrl.js

    'use strict';

var pokedexApp = angular.module('pokedexApp', []);

pokedexApp.controller('PokemonCtrl', function() {
    var vm = …
Run Code Online (Sandbox Code Playgroud)

javascript controllers angularjs

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

angularjs ×1

controllers ×1

javascript ×1