1
我正在嘗試使用角度全堆生成器注入一個工廠到控制器上,並且我沒有找到提供程序的問題,我在哪裏出錯? 我創建與用喲angular創建一個服務:工廠測試無法加載testProvider
NPM應用安裝-g發電機角fullstack
喲角fullstack chatApp
喲角:工廠試驗
應用程序/腳本/服務/ test.js
'use strict';
angular.module('chatApp')
.factory('test', function() {
// Service logic
// ...
var meaningOfLife = 42;
// Public API here
return {
someMethod: function() {
return meaningOfLife;
}
};
});
所以我在哪裏可以加載工廠我試圖加載在main.js文件中像這樣
應用程序/腳本/控制器/ main.js
'use strict';
angular.module('chatApp')
.controller('MainCtrl', function ($scope, test) {
console.log(test);
$scope.messages = 'this is a hardcoded test';
});
應用程序/腳本/ main.js
'use strict';
angular.module('chatApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
])
.config(function ($routeProvider, $locationProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'partials/main',
controller: 'MainCtrl'
})
.when('/login', {
templateUrl: 'partials/login',
controller: 'LoginCtrl'
})
.when('/signup', {
templateUrl: 'partials/signup',
controller: 'SignupCtrl'
})
.when('/settings', {
templateUrl: 'partials/settings',
controller: 'SettingsCtrl',
authenticate: true
})
.when('/about', {
templateUrl: 'partials/about',
controller: 'SettingsCtrl'
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
// Intercept 401s and redirect you to login
$httpProvider.interceptors.push(['$q', '$location', function($q, $location) {
return {
'responseError': function(response) {
if(response.status === 401) {
$location.path('/login');
return $q.reject(response);
}
else {
return $q.reject(response);
}
}
};
}]);
})
.run(function ($rootScope, $location, Auth) {
// Redirect to login if route requires auth and you're not logged in
$rootScope.$on('$routeChangeStart', function (event, next) {
if (next.authenticate && !Auth.isLoggedIn()) {
$location.path('/login');
}
});
console.log($location);
});
錯誤是:
304 Not Modified
14ms
angular.js (line 7997)
Error: [$injector:unpr] Unknown provider: testProvider <- test
http://errors.angularjs.org/1.2.11/$injector/unpr?p0=testProvider%20%3C-%20test
minErr/<@http://localhost:9000/bower_components/angular/angular.js:78
createInjector/providerCache.$injector<@http://localhost:9000/bower_components/angular/angular.js:3543
[email protected]://localhost:9000/bower_components/angular/angular.js:3670
createInjector/instanceCache.$injector<@http://localhost:9000/bower_components/angular/angular.js:3548
[email protected]://localhost:9000/bower_components/angular/angular.js:3670
[email protected]://localhost:9000/bower_components/angular/angular.js:3697
[email protected]://localhost:9000/bower_components/angular/angular.js:3718
@http://localhost:9000/bower_components/angular/angular.js:6777
ngViewFillContentFactory/<[email protected]://localhost:9000/bower_components/angular-route/angular-route.js:907
[email protected]://localhost:9000/bower_components/angular/angular.js:6228
[email protected]://localhost:9000/bower_components/angular/angular.js:5637
[email protected]://localhost:9000/bower_components/angular/angular.js:5542
[email protected]://localhost:9000/bower_components/angular/angular.js:5656
[email protected]://localhost:9000/bower_components/angular/angular.js:6248
[email protected]://localhost:9000/bower_components/angular-route/angular-route.js:865
[email protected]://localhost:9000/bower_components/angular/angular.js:12245
好像test.js沒有被加載,但我不知道如何使它加載 – mithereal
似乎就好像服務腳本不被包含在主視圖文件中一樣,我如何讓grunt包含新的gcreated指令,服務等進入主應用程序,從而可用(好像test.js沒有被加載,但我沒有知道如何加載它,你可以在底部的鏈接中看到test.js不存在,但user.js是[這是一個鏈接到應用程序的鏈接](http://hastebin.com/fiweyajaci.xml) – mithereal