Javascript 代码中有我不知道的错误';我不知道如何解决这个问题
我的网站只与fairfox合作,不与chrom合作 但是,当我在chrom上运行带有netbeams的html时,web运行得很好 我不知道该怎么办,我需要在接下来的10小时内提交 您可以在此处下载整个项目: 索引html:Javascript 代码中有我不知道的错误';我不知道如何解决这个问题,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,我的网站只与fairfox合作,不与chrom合作 但是,当我在chrom上运行带有netbeams的html时,web运行得很好 我不知道该怎么办,我需要在接下来的10小时内提交 您可以在此处下载整个项目: 索引html: <html ng-app="MyApp"> <head> <title>Web Site Student</title> <meta charset="UTF-8"> <meta
<html ng-app="MyApp">
<head>
<title>Web Site Student</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="_scripts/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="_scripts/angular.min.js"></script>
<script src="_scripts/angular-route.min.js"></script>
<script src="_scripts/myapp.js"></script>
<script src="_scripts/ctrols.js" type="text/javascript"></script>
<script src="_scripts/json.js" type="text/javascript"></script>
<link href="_css/bootstrap.min.css" rel="stylesheet" />
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteStudent</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#/list">Data</a></li>
<li><a href="#/analysis">Analysis</a></li>
<li><a href="#/monitor">Monitor</a></li>
</ul>
</div>
</nav>
<div ng-view>
</div>
</body>
myapp代码:
(function () {
'use strict';
angular.module('MyApp', [
"ngRoute"
]);
}());
(function () {
angular.module('MyApp')
.config(
function ($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider
.when("/list", {
templateUrl: "addon/list.html",
controller: "ListCtrl"
})
.when("/analysis", {
templateUrl: "addon/analysis.html",
controller: "AnalysisCtrl"
})
.when("/monitor", {
templateUrl: "addon/monitor.html",
controller: "MonitorCtrl"
})
.otherwise({
redirectTo: "/list"
})
});
}());
简单地说,您的代码是一团乱麻。有些地方有多余的字符,有些地方缺少字符。文件结构不好,引用的文件不存在(_css/stayle.css),缩进不正确 下次,请将您的代码上传到github,而不是一个有等待时间的随机网站和外语网站 为了更好地理解Angular及其文件结构,请阅读John Papa的Angular 1样式指南: 和/或托德的座右铭:
话虽如此,我认为您的主要问题在于ctrols.js和myapp.js文件 为了简单起见,我删除了“SuperCtrl”。当您更好地理解角度时,可以添加它。您的myapp.js文件应类似于以下内容:
(function () {
'use strict';
angular.module('MyApp', [
"ngRoute"
]);
}());
(function () {
angular.module('MyApp')
.config(
function ($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider
.when("/list", {
templateUrl: "addon/list.html",
controller: "ListCtrl"
})
.when("/analysis", {
templateUrl: "addon/analysis.html",
controller: "AnalysisCtrl"
})
.when("/monitor", {
templateUrl: "addon/monitor.html",
controller: "RemoveCtrl"
})
.otherwise({
redirectTo: "/list"
})
});
}());
ctrols.js文件中的每个控制器应采用类似的格式:
(function () {
'use strict';
angular
.module('MyApp')
.controller('ControllerName', functionName); // ControllerName & functionName can be the same name, but not required.
functionName.$inject = ['$scope'];
function functionName($scope) {
// Controller code here
}
})();
这应该足以让你朝着正确的方向前进
更新代码后,我可以看到数据和分析选项卡的UI:
这对狐狸不公平谢谢你的快速回复我才刚开始学习lern angularjs yasterdy,我会更好我希望时间很短:)你能上传更改吗?你做的更改对我仍然不起作用,我不知道我想知道你做了什么,你在控制台日志中看到了什么错误?尝试解决这些问题,如果无法解决,请更新您的帖子以包含错误和您所做的更改。确保您的库以正确的顺序导入(即先导入jQuery再导入其他库)。另一方面,您还没有选择正确的答案回答之前提出的问题。如果有任何答案对你帮助最大,请在上一个问题中勾选它。我更新了我更改的内容并添加了带有错误的图像。我希望你能在这个问题上帮助我,因为我确实需要你的帮助
(function () {
'use strict';
angular
.module('MyApp')
.controller('ControllerName', functionName); // ControllerName & functionName can be the same name, but not required.
functionName.$inject = ['$scope'];
function functionName($scope) {
// Controller code here
}
})();