gpt4 book ai didi

javascript - 无法在 Angular 中显示 View

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

使用以下代码我无法显示任何 HTML。我在控制台中没有收到任何错误。知道我做错了什么吗?

<小时/>

index.html

<!DOCTYPE html>
<html ng-app="KanbanBoard" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<script src="libs/angular.min.js"></script>
<script src="libs/angular-route.min.js"></script>
<script src="app/app.js"></script>
<script src="app/boards/boardsController.js"></script>
</body>
</html>
<小时/>

app.js

   'use strict';
var app = angular.module('KanbanBoard', ['ngRoute']);

(function () {

app.config(function ($routeProvider) {

$routeProvider.when("/boards", {
controller: "BoardsController",
templateUrl: "/app/boards/boardsView.html"
});

$routeProvider.otherwise({ redirectTo: "/boards" });

});

})();

Controller .js

'use strict';
(function () {
app.controller('BoardsController', ['$scope', function ($scope) {
$scope.users;
this.users = [
{
id: 0,
email: 'a@a.com',
name: 'A',
surname: 'B',
initials: 'AB',
boards: [
{
id: 0,
title: 'Welcome Board',
description: 'Board sample',
isArchived: false,
},
{
id: 1,
title: 'Project X',
description: 'Project X description',
isArchived: false,
}
]
}
];
$scope = this.users;
}]);
})();
<小时/>

boardView.html

<div ng-controller="BoardsController as boardsCtrl">
<div ng-repeat="user in boardsCtrl.users">
{{user.name + " " + user.surname}}
<ul>
<li></li>
</ul>

</div>
</div>

最佳答案

在您的网页正文中,您似乎缺少 ng-view:

<!DOCTYPE html>
<html ng-app="KanbanBoard" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>

<div ng-view></div> <!--this is required.-->

<script src="libs/angular.min.js"></script>
<script src="libs/angular-route.min.js"></script>
<script src="app/app.js"></script>
<script src="app/boards/boardsController.js"></script>
</body>
</html>
<小时/>

来自文档:

ngView is a directive that complements the $route service by including the rendered template of the current route into the main layout (index.html) file. Every time the current route changes, the included view changes with it according to the configuration of the $route service.

关于javascript - 无法在 Angular 中显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26860608/

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