当我在 Firefox 上使用 console.log 测试我的 index.html 时,它读到一个奇怪的错误,上面写着。我无法在 Google Chrome 或 IE 上运行 oage。
junk after document element
这个错误是由main.html页面引起的
<h1>This is my main</h1>
<h3>Scope value: {{ name }} </h3>
我只是在学习 angular.js,实际上我的代码与我遵循的本教程完全一样,但我无法弄清楚为什么不起作用。谁能指出我正确的方向并告诉我:
Why am I getting the console log error: Junk after document error, and why can't I make ngview and templateURL work on my site?
谢谢!
App.JS:
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/main.html',
controller: 'mainController'
})
.when('/second', {
templateURL: 'pages/second.html',
controller: 'secondController'
})
});
myApp.controller('mainController', ['$scope', '$log', function($scope, $log) {
$scope.name = 'Main';
}]);
myApp.controller('secondController', ['$scope', '$log', function($scope, $log) {
$scope.name = 'Second';
}]);
Index.HTML
<header> <nav class="navbar navbar-default"> <div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">AngularJS</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><i class="fa fa-home"></i>Home</a></li>
<li><a href="#/second"><i></i>Second</a></li>
</ul> </div> </nav> </header>
<div class="container">
<div ng-view></div>
</div>
Main.HTML
<h1>This is my main</h1>
<h3>Scope value: {{ name }} </h3>
Second.HTML
<h1>This is my second</h1>
<h3>Scope value (on second page): {{ name }} </h3>
最佳答案
代码无法在 IE 或 Chrome 上运行,因为它们没有内置的本地主机功能。 Firefox 可以。
关于错误,我不是 100% 肯定,但我相信它与浏览器本身对 Angular HTML 格式的支持有关。我现在正在上同样的类(class)并面临同样的问题。但除了 Firefox 中的那些错误外,该应用程序运行良好。
Chrome:没有错误。
MS Edge:没有错误。
IE:没有错误
===========================
更新
尝试使用 Brackets 文本编辑器,并使用实时预览功能。
在 Brackets 中打开 Index.HTML 页面并点击右上角的按钮。
关于angularjs - 文档元素错误后 Firefox Junk 上的 Angular.JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36631002/