$routeProvider
ng-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', ...
機能しています。