I want to load different templates for different screen sizes in a specific view.
Markup
<div id="phoneMetaDiv" class="visible-xs"></div>
<div id="tabletMetaDiv" class="visible-sm"></div>
<div id="desktopMetaDiv" class="visible-md"></div>
<div id="giantScrMetaDiv" class="visible-lg"></div>
Application script:
app.run(function ($rootScope) {
$rootScope.Views = {
Phone : 1,
Tablet : 2,
Desktop : 4,
GiantScr: 8,
};
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;
};
}
More 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>
And the error:
Error: [$parse:syntax] Syntax Error: Token '|' is unexpected, expecting [)] at column 20 of the expression [View(Views.Desktop | Views.GiantScr)] starting at [| Views.GiantScr)].
Does this mean that bitwise operations are not allowed inside ng-if?
source
share