Skip to content

Instantly share code, notes, and snippets.

@zhuangya
Created September 26, 2016 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuangya/38476c504d29d39d8d2bfae5e11b5060 to your computer and use it in GitHub Desktop.
Save zhuangya/38476c504d29d39d8d2bfae5e11b5060 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app="ing">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-gettext/2.3.8/angular-gettext.js"></script>
</head>
<body>
<h1>watch typeof</h1>
<div ng-controller="MainCtrl">
<p> <strong>without workaround</strong> </p>
<input type="range" ng-model="activity.length" min="1" max="10" step="1"> <span translate translate-n="activity.length" translate-plural="{{$count}} hours">1 hour</span>
<strong> typeof activity.length is: {{activity.length|typeof}} </strong>
<hr />
<p><strong> with workaround </strong></p>
<input type="range" ng-model="activity.length" min="1" max="10" step="1"> <span translate translate-n="getLength()" translate-plural="{{$count}} hours">1 hour</span>
<strong> typeof getLength() is: {{getLength()|typeof}} </strong>
</div>
<script>
angular.module('ing', ['gettext'])
.filter('typeof', function () {
return function (input) {
return typeof input;
}
})
.controller('MainCtrl', function ($scope) {
$scope.getLength = function () {
return Number($scope.activity.length);
}
$scope.activity = {
length: 3
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment