gpt4 book ai didi

javascript - 为什么我的 angularJS 路由不起作用,chrome'error [$injector :unpr] Unknown provider

转载 作者:行者123 更新时间:2023-11-28 01:30:53 34 4
gpt4 key购买 nike

我正在尝试使用 angularJS 的路由
但它不起作用
我不明白为什么
app.js

(function() {
var todoApp;

todoApp = angular.module('todoApp', ['ngRoute']);

todoApp.config([
┊ '$routeProvider', function($routeProvider) {
┊ ┊ $routeProvider.when('todo/day', {
┊ ┊ ┊ template: '<div class="box" ng-class="classname">Edit</div>',
┊ ┊ ┊ controller: function($scope) {
┊ ┊ ┊ ┊ $scope.classname = "edit";
┊ ┊ ┊ }
┊ ┊ }).otherwise({
┊ ┊ ┊ redirecTo: '/todo'
┊ ┊ });
┊ }
]);

todoApp.controller('todoCtrl', function($scope) {
┊ return console.log(123);
});

}).call(this);

这是我应用中的html

.html

  ┊ <div class="five wide column" ng-app="todoApp" ng-controller="todoCtrl">
┊ ┊ <div class="ui segment">
┊ ┊ ┊ <div ng-view></div>
┊ ┊ </div>
┊ </div>

chrome的控制台在这里

Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective  

Error: [$injector:cdep] Circular dependency found: ngViewDirective

最佳答案

首先,如果您还没有在 index.html 中包含 angular-route.js,请确保将其包含在内。您的脚本中有一些错误,如果可以的话,请尝试一下。

(function() {

var todoApp = angular.module('todoApp', ['ngRoute']);

todoApp.config(['$routeProvider',
function($routeProvider) {

$routeProvider.
when('todo/day', {
template: '<div class="box" ng-class="classname">Edit</div>',
controller: function($scope) {
$scope.classname = "edit";
}
}).otherwise({
redirectTo: '/todo'
});
}
]);

todoApp.controller('todoCtrl', function($scope) {
return console.log(123);
});
}).call(this);

关于javascript - 为什么我的 angularJS 路由不起作用,chrome'error [$injector :unpr] Unknown provider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30296530/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com