gpt4 book ai didi

angularjs - 在 Angular 引导的 MVC 应用程序中有条件地呈现 MVC 包

转载 作者:行者123 更新时间:2023-12-04 16:04:46 24 4
gpt4 key购买 nike

我已经使用 ASP.NET MVC 应用程序引导了 Angular。如何根据呈现的 Angular View 有条件地加载 MVC 包。

索引.cshtml

<!DOCTYPE html>

<html ng-app="maypp">
<body>

<div class="container">

@*HEADER*@
<div header></div>


<div ui-view></div>

@*FOOTER*@
<div footer></div>

</div>
@Scripts.Render("~/bundles/bundle1")
@Scripts.Render("~/bundles/bundle2")

</body>
</html>

我只需要为 Angular View 1 加载 bundle1。其他 View 需要同时包含 bundle1 和 bundle2。我使用的是 AngularJS,而不是 Angular 2。感谢任何回复。

最佳答案

你可以把它放在你的 cshtml View 的底部。但是,您可能希望用您的业务逻辑替换随机数检查器 :)

选项 1:

@section Scripts {

@if (new Random().Next(10) > 5)
{
@Scripts.Render("~/bundles/x")
}
else
{
@Scripts.Render("~/bundles/y")
}

}

选项 2:

捆绑包 1:
function startBundleOne(){
//bundle logic
}

捆绑 2:
function startBundleTwo(){
//bundle logic
}

AngularJS View :
if (something){
startBundleOne();
} else {
startBundleTwo();
}

选项 3:
var scriptPath;
if (something){
scriptPath = "pathA";
} else {
scriptPath = "pathB";
}
var script = document.createElement('script');
script.setAttribute('src',scriptPath);
document.head.appendChild(script);

关于angularjs - 在 Angular 引导的 MVC 应用程序中有条件地呈现 MVC 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50802608/

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