How do I use evaluate property for an object in LogicApp? - azure-logic-apps

I need following expression to use value of variable called StateTagName instead of hardcoded value of CurrentEastUSHDInsightsObject. How do I do that?
{
"inputs": "#json(variables('CurrentTags').CurrentEastUSHDInsightsObject)"
}

Correct syntax is not to use dot notation but square brackets
json(variables('CurrentTags')[variables('StateTagName')])

Related

if:true comparison inside the for loop

I want to do comparison in the if:true part inside for:each loop.
The answer I got from google is to create a new sub-component. But I really don't wanna go this route... Any other good options?
<template for:each={listData} for:item="obj">
<template if:true={obj.Id == CurrentId}>
</template>
Documentation
if:true|false={expression}
Use this directive to conditionally render DOM elements in a template.
The expression can be a JavaScript identifier (for example, person) or dot notation that accesses a property from an object (person.firstName). The engine doesn’t allow computed expressions (person[2].name['John']). To compute the value of expression, use a getter in the JavaScript class.
You can't use these kind of expression, but you can add to your object a property or a getter that evaluates to a boolean. Something like this:
this.listData = this.listData.map((elem) => {
const self = this;
return {
...elem,
get isCurrent() {
return this.Id == self.CurrentId;
}
};
});
Then you can use <template if:true={obj.isCurrent}>.

eslint selector syntax for nth child argument

am trying to match the following in a custom lint rule:
expect(element.getAttribute('checked')).toBe(true);
i'm attempting to use the following syntax in the selector:
"CallExpresssion[callee.object.arguments[0].callee.property.name='getAttribute']"(node) {
console.log(node);
},
but this doesn't work because of the arguments[0]. so i'm wondering if there's any way to do this query on an argument.
It is possible to access items in an array. The syntax is not really what you'd expect though. Instead of the normal bracket notation, you'd access it as a property: arguments.0
This is what your query could look like:
"CallExpresssion[callee.object.arguments.0.callee.property.name='getAttribute'](node) {
console.log(node);
}

AngularJS - ng-if if there is a specific value in array

I would like to trigger ngIf when there is a specific value in an array inside the scope.
So I have this on my scope:
var orders = [{
"order_no": 1,
"color": ["blue", "pink", "red"]
}, {
"order_no": 2,
"color": ["yellow", "blue", "white"]
}];
I would like to have an ngIf that shows one element if, for example, yellow is present in one of the color arrays (given that I would not know the data scope in advance, but knowing the structure in advance).
The only way I have found to do that would be when knowing the structure of the scope in advance, so fx ng-if="orders[1].color[0] === 'yellow'"
Thanks!
You can call the indexOf method of the color array inside your HTML template. This way, you don't need to pollute the $scope with additional methods.
Here's how: ng-if="order.color.indexOf('pink') !== -1"
Note: don't forget that expressions in AngularJS are different. One key factor to remember is that they are forgiving.
Forgiving: In JavaScript, trying to evaluate undefined properties generates ReferenceError or TypeError. In Angular, expression evaluation is forgiving to undefined and null.
This means that something like myCtrl.foo.bar.wa.la will evaluate to undefined which doesn't trigger ngIf. You can read more about it here.
You could do this as a function expression
ng-if="hasYellow()"
$scope.hasYellow = () => $scope.orders.some(
order => order.color.indexOf("yellow") > -1
);
Depending on the size of orders and how often it changes, it may be more efficient to just have a hasYellow property and update that when orders is changed.

Get dynamic scope array variable value in angularjs

I have a scope array variable which i am trying to access dynamically. Its value has been already set.
Its like this.
$scope.setp = { arr: [] };
$scope.setp.arr[0] = "sample Value";
When I am trying to access it dynamically as below I get undefined.
console.log($scope['setp.arr[0]']);
However I am able to access it directly using the following.
console.log($scope.setp.arr[0]);
The way of dynamically getting value of scope variable works fine for others but fails when the variable name contains square brackets i.e. [ ].
I followed this example but no success for scope variable containing array or square brackets [ ].
Also dynamically setting of scope array variable using $parse service works fine as in below.
var scopeVariable = $parse('setp.arr[0]');
scopeVariable.assign($scope, "new Value");
This won't work console.log($scope['setp.arr[0]']); as its trying to access a property setp.arr[0]. You can access it like console.log($scope['setp']['arr'][0]);

AngularJS evaluate an interpolation expression without printing to screen

I have an expensive function call that gets called once per loop, but I would like to set the return value of that to be a temporary variable that can be used directly within the loop.
This works by setting {{ val=fn(...) }}, but it also prints to the screen. Is it possible to do this without printing the value?
I've tried using one set of curly braces {} but it doesn't work.
Any ideas on how to do this?
Have you looked into "filters" or possibly doing the work in your JS code instead of the view?
Instead of a temporary variable, call a method when you need the value, and in this method, use a cached version of the result, or call your expensive method if the cached version is null/undefined. It will only call your expensive function once per iteration, and it won't call it if it's not needed. It won't print it unless you want to. Because each iteration of a ng-repeat spawns a new scope, each iteration will start with an empty cache.
e.g.:
$scope.cache = null
$scope.getValue = function() {
if (!this.cache) { // use typeof if 0 or false or empty string is valid!
this.cache = myExpensiveFunc()
}
return this.cache
}
Not 100% sure $scope.cache = null will be initialized for each scope of the iteration, you may need to check if 'this' hasOwnProperty 'cache' in getValue. So in your view, you only reference getValue() when you need to.
HTH!
edit: cache on scope, not in controller.

Resources