gpt4 book ai didi

javascript - 如何使用 AngularJS 替换 .asp include?

转载 作者:行者123 更新时间:2023-12-02 18:06:00 26 4
gpt4 key购买 nike

.aspx 站点构建一个小型框架。项目名为Dwarf并可在 GitHub 上获取。

我正在解决的问题是使用部分。例如,在我的一个页面中,侧边栏中有一个部分可以拉入 .html 文件。页面中的引用是

<!--#include file="/_includes/template/product-pages/product-links-contact-rep.html" --> 

如何集成 AngularJS 以在此处使用部分?

我在想

<!-- this is just an example -->
<script type=text/ng-template id=product-links-contact-rep.html>
<!-- Links -->
<ul>
<li><ahref="http://www.example.com/link1">link 1</a></li>
<li><ahref="http://www.example.com/link2">link 2</a></li>
</ul>
</script>

整个脚本都会进入页面?以及如何解决部分脚本的路由问题?

我有 Rails 背景,是 ASP 新手,也是 Angular 新手。因此,我很高兴有人指出我的知识差距,以便我可以自己做进一步的研究。

最佳答案

您可以开始使用(并不是说这是最好的)但满足您需求的方法是在 angularjs 中使用指令

这是代码

main.js

var app = angular.module('myApp', []);
app.controller('MyCtrl', function($scope) {


});
app.directive("sidebar",function(){
return {
restrict: 'A',
templateUrl: "product-links-contact-rep.html.html",
link : function(scope,element,attr) {
// Do Great things here with your sidebar
},
}
});

index.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>Side Bar</title>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>

<script type="text/javascript" src="main.js"></script>

</head>
<body ng-app="myApp">
<script type="text/ng-template" id="product-links-contact-rep.html.html">
<!-- Links -->
<ul>
<li><a href="http://www.example.com/link1">link 1</a></li>
<li><a href="http://www.example.com/link2">link 2</a></li>
</ul>
</script>
<div ng-controller="MyCtrl">
<div sidebar></div>
</div>
</body>
</html>

这里是可供引用的工作代码:http://plnkr.co/edit/NAR1g5?p=preview

关于javascript - 如何使用 AngularJS 替换 .asp include?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20103097/

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