gpt4 book ai didi

javascript - 如何在没有所有脚本文本的情况下将脚本包含到我的 cshtml 文件中

转载 作者:行者123 更新时间:2023-12-03 06:23:34 25 4
gpt4 key购买 nike

我有一个 asp.net cshtml 文件,但我必须包含带有 id 的脚本 html 才能使我的 ngRoutes 正常工作。到目前为止,我的 cshtml 文件如下所示:

<div ng-view></div>

<script type="text/ng-template id="one.html">
...very long html...
</script>
<script type="text/ng-template id="two.html">
...very long html...
</script>
<script type="text/ng-template id="three.html">
...very long html...
</script>
<script type="text/ng-template id="four.html">
...very long html...
</script>

我不想包含所有脚本,但需要它像指令一样显示。我怎样才能做这样的事情......

<div ng-view></div>
<div ng-include="'one.html''"></div>
<div ng-include="'two.html''"></div>
<div ng-include="'three.html''"></div>

我已经尝试过这种方式,但它不允许我将其包含在 Razor 文件中。

最佳答案

我假设您正在使用 ngRoute。在这种情况下,您可以在配置阶段在 RouteProvider 上设置模板 url:

angular.module('yourmodule', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/one', {
templateUrl: 'one.html',
})
.when('/two', {
templateUrl: 'two.html',
});
}])

关于javascript - 如何在没有所有脚本文本的情况下将脚本包含到我的 cshtml 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38753209/

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