how to pass function returns as an argument for another function in polymer - polymer-1.0

<span> {{_x(_y(‘c’))}}</span>
This is not working on polymer do you know why?
X and y are declared in polymer x is working and y is working by themselves but not both as the above syntax
‘C’ in my actual code is a parameter in dom-repeat

Related

"isNull" in AngulaJS with a non defind value

In angular JS I use the "isNull" function, the problem is that the value I put in it is not null but not defined. How can you make it behave as if the undefined value were null?

AngularJS assign function to scope member doesn't work

I'm new to AngularJS and I followed a tutorial to learn it. When I tried to assign a string literal to scope member it works, but it doesn't work if assigned a function instead. The code is as follow:
The result becomes the member value is assigned the definition text of the function, instead of the return value of the function. Any idea? Thanks very much.
tutorialName is a function, so you should use the function () inside the expression
<br> This tutorial is {{tutorialName()}} </br>

AngularJS: is 0 == 2? [duplicate]

This question already has answers here:
How to parseInt in Angular.js
(7 answers)
Closed 6 years ago.
I am scratching my head here. I am using angularJS and trying to use the expression that contains call to parseInt.
{{0 == 2}}
...prints out false as expected.)
However, when I am trying:
{{parseInt(0) == parseInt(2)}}
... it prints out... true !
How can this be possible?
Angular does not use JavaScript's eval() to evaluate expressions.
Instead Angular's $parse service processes these expressions.
Angular expressions do not have access to global variables like
window, document or location. This restriction is intentional. It
prevents accidental access to the global state – a common source of
subtle bugs.
Refer
In your html
Both parseInt(0) and parseInt(2) are undefined in your html.
So {{undefined==undefined}} is true.Beacause parseInt is a Javascript function.So you cant access the parseInt function in side {{}}. [Here parseInt is not a scope variable]
Solution
If you wish to do this,
define parseInt in your controller,
$scope.parseInt = parseInt;
Then you can use the parseInt method in your html
That's because parseInt is not defined in your scope.
http://jsfiddle.net/halirgb/Lvc0u55v/
You can't execute regular JS in an angular expression. Your expressions will be evaluated against the current scope. So, parseInt is undefined in the current scope.
If you set parseInt as a function reference, it will work.
$scope.parseInt = parseInt;
This is because the view is attached to the controller via scope.
So whatever we write in view either a variable or a function or anything it's rendered by appending $scope in front of it.
eg.
a is rendered as $scope.a in the view
So when we write parseInt, its rendered by $scope.parseInt which is not defined.
FIX- define $scope.parseInt = parseInt in the controller attached to the particular view
You have comparing both undefined values so result will be true.
You cannot call a javascript method(parseInt) via angular directives(ng-blur,ng-change,..) either you can achieve by making angular functions.
Solution 1:
{{0*1 == 2*1}}
Just do a trick to convert to Integer by multiply with 1 (0*1 = 0, 2*1 =1).
Solution 2:
{{parseInt(0) == parseInt(2)}}
Controller:
// To Convert specific format
$scope.parseInt = funtion(value){
return parseInt(value,10);
}
or
$scope.parseInt = parseInt;
reference here

How to assign a value in angular's $parse

I have a string reference to one of my scope values like this:
var reference_string = "form.name";
And I want to assign a value to the object it is referencing:
$scope.form.name = 'newvalue';
Looking around, I found 2 possible solutions: using plain JS or using the angular $parse function.
However, it seems like the $parse function only returns the value. Can I make it so that I can assign a new value?
ie. I want to do something like
var reference_string = "form.name";
var reference = getReference($scope, reference_string); // ideally using an angular in-built function like $parse
reference = 'newvalue'; // should have the same effect as $scope.form.name = 'newvalue';
The object returned by $parse has an assign() method for setting values.
var getter = $parse(reference_string);
getter.assign($scope, 'newValue');
Plunker demo ~ http://plnkr.co/edit/RlhXRpJvQ69ZdEkstyq8?p=preview
$parse is an Angular service which converts an expression into a function. The function can then be invoked and passed a context (usually scope) in order to retrieve the expression's value.
In addition, if the expression is assignable the returned function will have an assign property. The assign property is a function that can be used to change the expression's value on the given context.
enter link description here

Passing ng-directive to Leaflet L.popup().setContent()

Thank you for giving my question a look.
Goal: Pass an Angular directive to the .setContent() method of L.popup()
The Problem:
I need to run $compile on the directive in order for it to enter ng. But something like
.setContent($compile('<new_marker_form></new_marker_form'))
yields a
Failed to execute 'appendChild' on 'Node': The new child element is null.
as I bet the ng is trying to compile before leaflet has actually appeneded any HTML.
Not sure if this is better suited for Stack Overflow. Please let me know if I ought to move it.
The closing > is missing in your example, not sure if it is just a typo in the question.
And you haven't linked the compiled element to any scope, the result of $compile is not an element, but a linking function. You have to call the function by passing a scope object that you want the element to bind with (or a least an empty object).
var linkFn = $compile('<new_marker_form></new_marker_form>');
var element = linkFn({}); // or pass any scope object, may be $rootScope.$new() if you do not have one.
L.popup().setContent(element[0]); // use element[0] to pass a DOM instead of jQuery/jqLite object.
Or a one liner ..
L.popup().setContent($compile('<new_marker_form></new_marker_form>')({}));
Hope this helps.

Resources