位运算角内NG-如果 [英] Bitwise operation inside angular ng-if

查看:124
本文介绍了位运算角内NG-如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个特定的视图来加载不同的屏幕大小不同的模板。

I want to load different templates for different screen sizes in a particular view.

标记

<div id="phoneMetaDiv"      class="visible-xs"><!-- Visible on phones  --></div>
<div id="tabletMetaDiv"     class="visible-sm"><!-- Visible on tablets  --></div>
<div id="desktopMetaDiv"    class="visible-md"><!-- Visible on desktops --></div>
<div id="giantScrMetaDiv"   class="visible-lg"><!-- Visible on giant screens --></div>

应用脚本:

app.run(function ($rootScope) {


    $rootScope.Views = {
            Phone   : 1, //0001
            Tablet  : 2, //0010
            Desktop : 4, //0100
            GiantScr: 8, //1000
    };

    if($("#giantScrMetaDiv").is(":visible"))
        $rootScope.CurrentView = $rootScope.Views.GiantScr;
    else if($("#desktopMetaDiv").is(":visible"))
        $rootScope.CurrentView = $rootScope.Views.Desktop;
    else if($("#tabletMetaDiv").is(":visible"))
        $rootScope.CurrentView = $rootScope.Views.Tablet;
    else if($("#phoneMetaDiv").is(":visible"))
        $rootScope.CurrentView = $rootScope.Views.Phone;
    else
        throw "invalid view";

    $rootScope.View = function (value) {
        return ($rootScope.CurrentView & value) !=0;
    };
}

更多HTML

<div ng-if="View(Views.Desktop | Views.GiantScr)"> Include for template 1... <div>
<div ng-if="View(Views.Phone)"> Include for template 2... <div>

和误差:

Error: [$parse:syntax] Syntax Error: Token '|' is unexpected, expecting [)] at column 20 of the expression [View(Views.Desktop | Views.GiantScr)] starting at [| Views.GiantScr)].

这是否意味着位运算不NG-如果入内?

Does this mean bitwise operations are not allowed inside ng-if?

推荐答案

|用于过滤器,所以我想没有,只写一个function.and角前pression语言不是javascript.There有很多不同之处。

"|" is used for filters , so I guess not, just write a function.and Angular expression language is not javascript.There are a lot of differences.

http://docs.angularjs.org/guide/ex$p$pssion

您必须写一个过滤器或类似功能按位或

You'll have to write a filter or a function like "bitwise-or"

这篇关于位运算角内NG-如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆