Angular ng If not working with razor syntax

微笑、不失礼 提交于 2019-12-24 10:51:02

问题


I am using Angular Js with Razor.

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

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

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... ?


回答1:


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'">


来源:https://stackoverflow.com/questions/27673786/angular-ng-if-not-working-with-razor-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!