本文介绍了Angular ng如果不能使用razor语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Razor与Angular Js配合使用.

I am using Angular Js with Razor.

@{
    var pageMode = (string) ViewBag.PageMode;
}

<div ng-if="@pageMode == 'answer'">
   <h2>Greetings</h2>
</div>

ViewBag.PageMode 中的值是"answer",如果未渲染,则仍为ng.即问候"消息不起作用.

Value is in ViewBag.PageMode is "answer", still the ng if does not render. i.e "Greetings" message does not work.

我在这里做错了什么...?

What am I doing wrong here... ?

推荐答案

您不能在 ng-if 之类的指令中使用 var pageMode 变量.您需要使用 $ scope 变量.

you cant use var pageMode variable inside directives like ng-if. you need to use $scope variable.

所以,您能做的最简单的事情是

so, simplest thing u can do is,

@{
    var pageMode = (string) ViewBag.PageMode;
}

<input type="hidden" ng-model="pageMode" ng-init="pageMode = '@pageMode'">


<div ng-if="pageMode == 'answer'">

这篇关于Angular ng如果不能使用razor语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 11:58