jquery - How to get localized terms from attributes with directives -


i using library pascal precht localize application. created directive should localized terms attributes placed in button this:

<button type="submit" ng-click="savedepartment(department)" ng-messages ng-success="{{'successful'|translate}}" ng-failure="{{'failure'|translate}}">     {{'save'|translate}} </button> 

this directive

module.directive('ngmessages', function() {     return {         restrict: 'a',         scope: {             ngsuccess:"=",             ngfailure:"="         },         link: function(scope, element, attr) {             var success = attr.ngsuccess;             var failure = attr.ngfailure;             scope.$watch(function(){                 scope.ngsuccess = success,                 scope.ngfailure = failure             });         }     }; }); 

this controller button

module.controller('departmentcontroller', function($scope, departmentservice){     $scope.savedepartment = function(department){         departmentservice.savedepartment(department).then(function(data){             var message = '';             if(data == true) {                message = $scope.success;             } else {                message = $scope.failure;             }             //...         });     } }); 

but getting error

error: [$parse:syntax] syntax error: token '{' invalid key @ column 2 of expression [{{'success'|translate}}] starting @ [{'success'|translate}}]. 

it works if pass directly string literal instead of localized texts. there workaround this?


edit

i think issue complicated according article/branch apply translation element's attributes

there many other pages don't understand translate directive conflicts html5 attribute , i've been reading doc https://angular-translate.github.io/docs/#/guide/05_using-translate-directive, still cannot find something. tried workaround , kissed goodbye custom message. later linking directive showed custom message this

templateurl: '<div>{{message}}</div' 

and replaced this. success not anymore text boolean variable

templateurl: '<div ng-if="success">{{"success"|translate}}</div>'         + '<div ng-if="!success">{{"failure"|translate}}</div>' 

with first approach wanted pass through attributes custom messages. let's if in enterprise/department wanted show "department saved". in employee context "employee saved" or "employee not saved", show "changes made successfully" or "changes not saved" everywhere , translated in respective set language.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -