0

$routeProviderng-view にテンプレートをロードしない Angular JS アプリケーションを使用しています。と を設定しまし<html data-ng-app="myApp"><section data-ng-view></section

テンプレートをロードすることも (XHR を作成することもありません)、他のパスにリダイレクトすることもありません (/#/foo/bar/foo/エラーをスローしません。

これは私の構成です:

angular.module('myApp', ['myAppFilters'])
    .config [
        '$routeProvider',
        ($routeProvider) ->
            $routeProvider
                .when '/:year/:month',
                    templateUrl: 'partials/detail.html'
                    controller: DetailCntl
                .when '/:user/:year/:month',
                    templateUrl: 'partials/detail.html'
                    controller: DetailCntl
                .otherwise
                    redirectTo: '/'
    ]

編集:コンパイルされたJSは次のとおりです。

angular.module('myApp', ['myAppFilters']).config([
    '$routeProvider', function($routeProvider) {
      return $routeProvider.when('/:year/:month', {
        templateUrl: 'partials/detail.html',
        controller: DetailCntl
      }).when('/:user/:year/:month', {
        templateUrl: 'partials/detail.html',
        controller: DetailCntl
      }).otherwise({
        redirectTo: '/'
      });
    }
  ]);

編集#2:私は自分で解決策を見つけましたfactories.coffee:設定を上書きした次の行がありました:

angular.module('myApp', []).factory 'api', ($http, $q, $cacheFactory) ->
...

これで、構成が割り当てられて@myApp使用され、@myApp.factory 'api', ...機能しています。

4

1 に答える 1

0

私は自分で解決策を見つけました:factory.coffeeに次の行があり、構成を上書きしました:

angular.module('myApp', []).factory 'api', ($http, $q, $cacheFactory) ->
...

これで、構成が割り当てられて@myApp使用され、@myApp.factory 'api', ...機能しています。

ご協力ありがとうございました。

于 2013-09-12T13:54:12.813 に答える