gpt4 book ai didi

javascript - Uncaught Error : Unknown provider: $rootScopeProvider <- $rootScope

转载 作者:行者123 更新时间:2023-12-03 08:02:48 25 4
gpt4 key购买 nike

我的问题是 angularjs 中的模板 Url。

因此,当我将此代码放入编辑器并运行它时,它可以完美运行:

HTML:

<!DOCTYPE html>
<html lang= "en">

<head>
<meta charset="UTF-8" />
<title>Angular Js</title>

<script type = "text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src = "https://rawgit.com/nirus/Angular-Route-Injector/master/dist/routeInjector.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>

<body ng-app = "app">
<div ng-view></div>
</body>
</html>

Js:

var app = angular.module('app', [])

app.config(function($routeProvider){

$routeProvider.when('/', {
template: 'page',

})

.when('/helloUser', {
template: "ds"

})

.otherwise({
redirectTo: '/'
})

})

enter image description here

效果很好,但是当我尝试放置 templateUrl 时,这里就是我的示例代码:

index.html

<!DOCTYPE html>
<html lang= "en">

<head>
<meta charset="UTF-8" />
<title>Angular Js</title>

<script type = "text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src = "https://rawgit.com/nirus/Angular-Route-Injector/master/dist/routeInjector.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>

<body ng-app = "app">
<div ng-view></div>
</body>
</html>

页面.html:

Hello World

main.js:

var app = angular.module('app', [])

app.config(function($routeProvider){

$routeProvider.when('/', {
templateUrl: 'page.html'

})

.when('/helloUser', {
template: "ds"

})

.otherwise({
redirectTo: '/'
})

})

enter image description here

编辑:

1投反对票接受您必须注入(inject) ngRoute 模块:

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

不工作: enter image description here

最佳答案

您必须注入(inject) ngRoute 模块:

<script src="angular-route.js">
var app = angular.module('app', ['ngRoute'])

关于javascript - Uncaught Error : Unknown provider: $rootScopeProvider <- $rootScope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34519390/

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