Skip to content

Instantly share code, notes, and snippets.

@sivajankan
Created January 16, 2014 22:02
Show Gist options
  • Save sivajankan/8464317 to your computer and use it in GitHub Desktop.
Save sivajankan/8464317 to your computer and use it in GitHub Desktop.
<!doctype html>
<html ng-app>
<head>
<meta name="description" content="AngularShowHide_WithUnderscore" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>
</head>
<body>
<div ng-controller="Controller">
<form name="form" class="css-form" novalidate>
Show/Hide:
<select id="iSelect" ng-model="OCCLUSION_LEFT" name="uSelect">
<option value=>Select</option>
<option value='0'>Hide0</option>
<option value='1'>Show1</option>
<option value='2'>Hide2</option>
<option value='3'>Labels only</option>
<option value='4'>Hide4</option>
<option value='5'>Inputs only</option>
<option value='6'>Name Only</option>
<option value='7'>Email Only</option>
</select>
<br />
<br />
<label ng-show="canShow('OCCLUSION_LEFT', ['1'])">Underscore</label>
<br />
<label ng-show="canShow('OCCLUSION_LEFT', ['1','3','6'])">Name:</label>
<input ng-show="canShow('OCCLUSION_LEFT', ['1','5','6'])" type="text" ng-model="user.name" />
<br />
<label ng-show="canShow('OCCLUSION_LEFT', ['1','3','7'])">E-mail: </label>
<input ng-show="canShow('OCCLUSION_LEFT', ['1','5','7'])" type="email" ng-model="user.email" />
<br />
</form>
</div>
</body>
</html>
var underscore = angular.module('underscore', []);
underscore.factory('_', function() {
return window._; // assumes underscore has already been loaded on the page
});
function Controller($scope) {
$scope.canShow = function(field, arr) {
return _.contains(arr, $scope[field]);
//return arr.lastIndexOf($scope[field]) != -1;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment