Javascript MVC4&;将ngAnimate用作依赖项时出现AngularJS错误
我不熟悉角度和依赖注入。我在页面加载时收到以下错误。我正在尝试在.Net/MVC4中创建一个类似的表单向导。非常感谢您的帮助Javascript MVC4&;将ngAnimate用作依赖项时出现AngularJS错误,javascript,angularjs,asp.net-mvc-4,dependency-injection,Javascript,Angularjs,Asp.net Mvc 4,Dependency Injection,我不熟悉角度和依赖注入。我在页面加载时收到以下错误。我正在尝试在.Net/MVC4中创建一个类似的表单向导。非常感谢您的帮助 :[$injector:unpr]未知提供程序:$$qProvider您创建了两次模块,正在加载的第二个模块将替换第一个模块。我不确定您希望依赖项的顺序,但您可能只需要一个应用程序: var myGllApp = angular.module('GllApp', ['ngAnimate', 'ui.router']); 稍后加载控制器脚本,并通过不将依赖项列表传递到an
:[$injector:unpr]未知提供程序:$$qProvider您创建了两次模块,正在加载的第二个模块将替换第一个模块。我不确定您希望依赖项的顺序,但您可能只需要一个应用程序:
var myGllApp = angular.module('GllApp', ['ngAnimate', 'ui.router']);
稍后加载控制器脚本,并通过不将依赖项列表传递到angular.module
,将其添加到现有模块中:
angular.module('GllApp')
.controller('LongFormController', ['$scope', function ($scope) {
您将创建两次模块,正在加载的第二个模块将替换第一个模块。我不确定您希望依赖项的顺序,但您可能只需要一个应用程序:
var myGllApp = angular.module('GllApp', ['ngAnimate', 'ui.router']);
稍后加载控制器脚本,并通过不将依赖项列表传递到angular.module
,将其添加到现有模块中:
angular.module('GllApp')
.controller('LongFormController', ['$scope', function ($scope) {
我已经重构了您发布的代码并添加了注释。试试这个,看看你是否收到另一个错误 这是假设您正在加载:第一个代码段>第二个代码段
(function () {
//use this inside of the SC function or else use strict will be used globally
//and cause unexpected results
'use strict';
// Create our app and inject ngAnimate and ui-router
// You don't need to create this variable if it is for scoping reasons,
// since you have already created a defined scope within the Self-Calling function
angular.module('GllApp', ['ngAnimate', 'ui.router'])
.config(function ($stateProvider, $urlRouterProvider) {
// Catch all route
// By default send user to question one
$urlRouterProvider.otherwise('/home');
$stateProvider
// Route to show start of form
.state('home', {
url: '/home',
templateUrl: 'form.html',
controller: 'LongFormController'
})
// Route to show start of form
.state('home.q01', {
url: '/home/q01',
templateUrl: 'form-q01.html'
});
});
})();
(function () {
'use strict';
angular.module('GllApp', ['ngAnimate']) //since you are not using stateProvider here you do not need to inject ui.router
.controller('LongFormController', ['$scope', function ($scope) {
// do stuff
}]);
})();
我已经重构了您发布的代码并添加了注释。试试这个,看看你是否收到另一个错误 这是假设您正在加载:第一个代码段>第二个代码段
(function () {
//use this inside of the SC function or else use strict will be used globally
//and cause unexpected results
'use strict';
// Create our app and inject ngAnimate and ui-router
// You don't need to create this variable if it is for scoping reasons,
// since you have already created a defined scope within the Self-Calling function
angular.module('GllApp', ['ngAnimate', 'ui.router'])
.config(function ($stateProvider, $urlRouterProvider) {
// Catch all route
// By default send user to question one
$urlRouterProvider.otherwise('/home');
$stateProvider
// Route to show start of form
.state('home', {
url: '/home',
templateUrl: 'form.html',
controller: 'LongFormController'
})
// Route to show start of form
.state('home.q01', {
url: '/home/q01',
templateUrl: 'form-q01.html'
});
});
})();
(function () {
'use strict';
angular.module('GllApp', ['ngAnimate']) //since you are not using stateProvider here you do not need to inject ui.router
.controller('LongFormController', ['$scope', function ($scope) {
// do stuff
}]);
})();
我刚刚在我的项目中解决了这个问题。根本原因是我依赖于“angular animate”:“~1.3.0”,因此bower使用angular v1.3,尽管项目的其余部分依赖于angular 1.2 只用
"angular-animate": "~1.2.0"
而不是
"angular-animate": "~1.3.0"
在您的bower.json文件中。在
bower安装之后
一切都应该正常 我刚刚用我的项目解决了这个问题。根本原因是我依赖于“angular animate”:“~1.3.0”,因此bower使用angular v1.3,尽管项目的其余部分依赖于angular 1.2
只用
"angular-animate": "~1.2.0"
而不是
"angular-animate": "~1.3.0"
在您的bower.json文件中。在
bower安装之后
一切都应该正常 你有angular.module('GllApp',['longFormController']…你有名为longFormController的模块吗?还有语法错误?(即longFormController)。我用新代码更新了上面的代码。我仍然收到相同的错误。你有angular.module('GllApp',['longFormController']…您有名为longFormController的模块吗?还有语法错误?(即longFormController)。我使用新代码更新了上面的代码。我仍然收到相同的错误。我收到的错误来自于不正确加载的anugular动画文件。我使用上面的代码从cdn中拉取了相同的文件,并且没有错误。我收到的错误来自于不正确加载的anugular动画文件.我用上面的代码从cdn中提取了相同的文件,它工作正常,没有错误。