How to remove in angular js? - javascript

The angular expression is {{ notification.noti_val }}.
The value stored in the expression is saha like own wall.
How can I remove the characters?

You need to specify your value as safe html. In angular you can use $sceservice to do so. I have created this jsbin explaining the use case and it fixes your issue

Related

Uppercase condition for polymer template

How to apply upperCase condition in template if in polymer. My code is:
if="[[ifIsOfType(abc.status,'final'.toUpperCase())]].
I applied this but its not working.
I believe Polymer cannot parse complex expressions in the HTML attributes since 1.0. So you have to move your conversion to the function you are calling.

How to use ng-translate with variables resolved from controller?

I'm using ng-tranlate for i18n.
I'd like to combine a translated label together with a variable resolved from controller binding. How can I achieve the following?
<div translate="my.lang.text">some more: {{controller.attribute}}</div>
This does not work, and ng-translate ignores any content between the divs. why?
The translate directive will replace the content of the element with the translation you pass to it.
The use case you are describing looks like a parameterized translation. If you want to keep the use of the directive, you could pass the variable through the translate-values directive:
<div translate="my.lang.text"
translate-values="{value: 'some more: ' + controller.attribute}"></div>
You have to specify that your translation is parameterized:
JSON
"my.lang.text": "This is a parameterized string {value}"
I believe the translate directive replaces all the element's content with the translation.
In this case, you probably want to use the translate filter instead.
<div>{{'my.lang.text' | translate}} some more: {{controller.attribute}}</div>
As an alternative, you could also avoid this issue by giving the translated value it's own element.
<div><span translate="my.lang.text"></span> some more: {{controller.attribute}}</div>
If the translation is always intended to have have a value appended to it, then using a parameterized translation is probably the best solution (as suggested by Michael https://stackoverflow.com/a/33419608/90305)

How to get a filtered angular string as a js function parameter?

I want to have a string that goes through angular's filter as a parameter for a javascript function. Angular doesn't parse it, how do I fix this?
<input type="text" ng-required="true" ng-model="foobar"
oninvalid="this.setCustomValidity({{ 'String' | myfilter }})">
The {{ .. }} does not go through Angular's parsing. If I remove the double quotation marks it still doesn't work as Angular 'fixes' it to be oninvalid="this.setCustomValidity("{{
Also, if there is another, more angular way of customizing the browser validation message, that would do the trick for me also.
You might want to read the angular documentation for input, in particular the example plunker provides the solution to your question.
If you still want a hint on what to do to use a filter in your argument please provide information about your oninvalid directive.
You can pass foobar directly
oninvalid="this.setCustomValidity({{ 'String' | myfilter(foobar) }})"

Angular SweetAlert with directives and translate

im currently using Angular implementation of the
Sweet alert
I want to pass to the title an Angular directive with translate
This is the variable I'm passing as title
{{ 'register.confirmation_modal.SUPERIOR_MESSAGE' | translate }}
And using Angular Compile Service
var translate_title = "<span>{{ 'sa.title' | translate }}</span>";
var compiled_title = $compile(translate_title)($scope);
and using html: true, in Sweet alert options
But i'm getting an object and it's being printed like the follow image
I tried using .innerHTML but it removes the Tags and gets the literal string with the curly braces {{ }}
JSON.stringify didn't worked either.
Any advice?
Credits to #Claies for pointing me to the solution
Instead of using $compile I solved my issue using the Filter translate from Angular translate
This did the trick:
var n = $filter('translate')('sa.title');
Regards.

Angular JS encoded double quotes not working

I am using ngInit to pass variables from PHP to my Angular JS Controller.
In some situations the passed string might contain encoded '"' (Double quotes ")
<div data-ng-controller="UserController" data-ng-init='init({"test":""My Test Input""})'>
</div>
But when this happens I am getting the following error in Angular JS :
http://errors.angularjs.org/1.3.13/$parse/syntax?p0=My&p1=is%20unexpected%2C%20expecting%20%5B%7D%5D&p2=16&p3=init(%7B%22test%22%3A%22%22My%20Test%20Input%22%22%7D)&p4=My%20Test%20Input%22%22%7D)
Please help
Try
<div data-ng-controller="UserController" data-ng-init='init({"test":"\"My Test Input\""})'>
This is an improper use of ng-init and you should run your code in controller instead
From docs:
The only appropriate use of ngInit is for aliasing special properties of ngRepeat, as seen in the demo below. Besides this case, you should use controllers rather than ngInit to initialize values on a scope.

Categories

Resources