Angular $routeProvider 和 Controller 作为语法

Angular $routeProvider and Controller As Syntax

谁能告诉我将 $routeProviderController as syntax 一起使用是否有效?我在从 this.foo 所在的控制器访问 <h1>{{kickController.foo}}</h1> 时遇到问题。

angular.module('ucp.kick', ['ngRoute']).config(function($routeProvider, APP_BASE_URL) {
  return $routeProvider.when(APP_BASE_URL + 'kicks', {
    reloadOnSearch: false,
    navitem: true,
    name: 'Kicks',
    templateUrl: 'kick/partials/kick.html',
    controller: 'kick as KickController'
  });
});

You could not add controllerAs syntax in controller option of $routeProvider.when.

您应该使用已提供的 controllerAs 选项来获取字符串格式的控制器别名,& controller 也接受将被视为 angular 控制器的字符串。

代码

$routeProvider.when(APP_BASE_URL + 'kicks', {
    reloadOnSearch: false,
    navitem: true,
    name: 'Kicks',
    templateUrl: 'kick/partials/kick.html',
    controller: 'KickController'
    controllerAs: 'kick' //controller alias taken out from controller option
});

controller: 'KickController as kick'

Doc Link