Angular ng If not working with razor syntax

2019-08-10 22:33发布

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条回答
乱世女痞
2楼-- · 2019-08-10 22:58

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'">
查看更多
登录 后发表回答