gpt4 book ai didi

javascript - 使用 ASP.NET 开发服务器呈现 Angular JS 部分 View

转载 作者:行者123 更新时间:2023-11-29 19:44:15 27 4
gpt4 key购买 nike

我目前正在尝试使用 Visual Studio 2010 来学习一些 Angular JS,但在呈现局部 View 时遇到了问题。我有一个 shell 页面 index.html 和一个在 /partials/list.html 中包含一些个人数据的表。当用户单击位于 list.html 中表格中的按钮时,他们应该被带到另一个局部 View edit.html。当我运行该项目时,我在浏览器中将其作为 url:http://localhost:62807/index.html#/部分 View list.html 被注入(inject)到需要的地方。这是这两件事的样子:

index.html

<!DOCTYPE html>
<html>
<head>
<title>Angular JS Routing</title>
<link rel="stylesheet"
href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"/>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css"
rel="stylesheet">
</head>
<body>
<div ng-app="enterprise" ng-controller="AppController">
<a href="#"><h2>Enterprise Crew</h2></a>
<ng-view></ng-view>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>

这是从 index.html 注入(inject)到 ng-view 标签中的部分 View

<table class="table table-striped" style="width: 250px">
<thead>
<tr>
<td>Name</td>
<td>Description</td>
<td> <a href="/new"><i class="glyphicon glyphicon-plus-sign"></i></a>

</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in crew">
<td>{{person.name}}</td>
<td>{{person.description}}</td>
<td><i class="glyphicon glyphicon-edit"></i></td>
</tr>
</tbody>
</table>

这是渲染后的样子: enter image description here

当用户单击加号时,他们需要转到另一个局部 View edit.html,它与 list.html 位于相同的局部文件夹中。它的 HTML 看起来像

编辑.html

<form action="">
<input ng-model="person.name"/>
<input ng-model="person.description"/>
<button ng-click="save()" class="btn-primary">Save</button>
save function not yet implemented
</form>

当我在浏览器中访问 URL http://localhost:62807/index.html#/ 时,一切都正常加载,并且 list.html 部分 View 被注入(inject)到需要的地方是。当我将鼠标悬停在加号按钮上时,我会看到 localhost:62807/new 的 URL 预览。单击时应注入(inject) edit.html 部分 View ,但我收到 404 错误。

这是 JS。

angular.module('enterprise',['ngRoute'])
.config(function($routeProvider){
$routeProvider
.when("/",{templateUrl:"partials/list.html"})
.when("/new",{templateUrl:"/partials/edit.html"})
})
//this is the that iterated over in the partial views ng-repeat
function AppController($scope){
$scope.crew =[
{name:'Picard',description:'captain'},
{name: 'Riker',description:'number 1'},
{name:'Word',description:'Security'}
]
}

我相信问题出在路由的某个地方。在我遵循的视频教程中,我注意到我在运行应用程序时获得的 URL 中包含项目名称或页面名称(在本例中,index.html 包含在 URL 中)。我很好奇为什么 list.html View 首先被正确注入(inject),而每当我尝试导航到 /new edit.html 部分 View 时却没有正确注入(inject)。我在本地玩弄这一切,所以我想首先让它工作,然后了解交易是什么以及为什么 list.html 局部 View 会呈现而 edit.html 不会呈现。

最佳答案

我认为 url 应该是

<a href="#/new"><i class="glyphicon glyphicon-plus-sign"></i></a>

关于javascript - 使用 ASP.NET 开发服务器呈现 Angular JS 部分 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20953751/

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