javascript - Use angular-translate to set placeholder value onblur -
i new angular. implementing localization in project. i've got many inputs , must translate placeholders. in html have this
<input type="email" placeholder="{{ 'translation_key' | translate }}" onfocus="this.placeholder=''" onblur="this.placeholder='{{ 'translation_key' | translate }}'" required>
but part of code doesn't work:(
onblur="this.placeholder='{{ 'translation_key' | translate }}'"
how set translated value placeholder onblur? i'll appreciate help!
this approach problem jsfiddle:
html:
<div ng-app="myapp" ng-controller="myctrl"> <input type="email" placeholder="{{placeholder}}" ng-focus="setplaceholder()" ng-blur="setplaceholder('translation_key')" required> </div>
js:
angular.module('myapp', []) .controller('myctrl', function ($scope, $filter) { $scope.placeholder = $filter('translate')('translation_key'); $scope.setplaceholder = function (data) { $scope.placeholder = $filter('translate')(data); }; }) .filter('translate', function () { return function (data) { return data; }; });
Comments
Post a Comment