AngularJS expression with HTML is adding quotes? - angularjs

I'm trying to echo the following HTML expression (got it from decoded jSON):
<ion-item>Dresses</ion-item></ion-item>
Using this:
<ion-item-group *ngFor="let category of categories"><ion-item-divider color="light">{{category.name}}</ion-item-divider>{{category.links}}</ion-item-group>
But the result is:
<ion-item-group><ion-item-divider color="light">Women Clothes</ion-item-divider><ion-item><a href="/category/latest-collection/women/dresses">Dresses</a></ion-item><ion-item></ion-item-group>
Any ideas? :-(

Related

ng-repeat not working in ui-popover-html

When ng-repeat is used in ui-popover-html, getting error -
Token 'item' is an unexpected token .
Code is given below:
<div uib-popover-html="'<span ng-repeat='item in ${this.myList}'>{{item}}</span>'"
popover-trigger="'mouseenter'"
popover-placement="auto bottom-right">
</div>
I don't want to use uib-popover-template. Need to achieve using uib-popover-html.

ngTagsInput get and parse data from database

When I use ngTagsInput before send to database I do:
angular.toJson($scope.tags);
When I make get I receive something like this in my scope {{}}:
[{"text":"abc"},{"text":"cba"},{"text":"tag"}]
What can I do to show my tags like this:
abc, cba, tag
In the template:
<span ng-repeat="(key, value) in tags"><span ng-if="!$first">, </span><span>{{value.text}}</span></span>
Or with Underscore in code:
var str = _.pluck(list, 'text').join(', ')
Other options here: Show an aggregated list in angularjs

Unable to Locate an Element using xpath for live updating fields

Every time the request id changes on selecting a live update field.
Am trying to get the request id through the xpath
This is the source code.
<form id="itemscreen334-33504-" class="itemscreen addMode v_334 ajaxForm form-initialized" method="POST" enctype="multipart/form-data" requestid="18310" style="visibility: visible; opacity: 1;">
Java Code:
WebElement form = driver.findElement(By.xpath("//form[Class='itemscreen addMode v_334 ajaxForm form-initialized')]"));
System.out.println("form-->" + form);
String requestNo = form.getAttribute("requestid");
System.out.println("requestNo----------->" + requestNo);
Selenium Error:
Exception in thread "main"
org.openqa.selenium.InvalidSelectorException: The given selector
//form[Class='itemscreen addMode v_334 ajaxForm form-initialized')] is
either invalid or does not result in a WebElement. The following error
occurred: InvalidSelectorError: Unable to locate an element with the
xpath expression //form[Class='itemscreen addMode v_334 ajaxForm
form-initialized')] because of the following error: [Exception... "The
expression is not a legal expression." code: "12" nsresult:
"0x805b0033 (SyntaxError)" location: ""]
How can i get the request id using xpath?
Actually you are providing wrong xpath, your xpath expression is looks like cssSelector, Try as below :-
WebElement form = driver.findElement(By.cssSelector("form.itemscreen.addMode.v_334.ajaxForm.form-initialized"));
String requestNo = form.getAttribute("requestid");
System.out.println("requestNo----------->" + requestNo);
Or if you want to use xpath try as below with correct xpath :-
WebElement form = driver.findElement(By.xpath("//form[#class = 'itemscreen addMode v_334 ajaxForm form-initialized']"));
String requestNo = form.getAttribute("requestid");
System.out.println("requestNo----------->" + requestNo);
Note :-if you want partial match with class attribute, you should use xpath as By.xpath("//form[contains(#class, 'itemscreen addMode')]") and cssSelector as By.cssSelector("form.itemscreen.addMode")

How do I ng-init a variable with nothing?

This line currently triggers an error because probably there is nothing after the second =.
What value should return from php to tell filterSubject that is empty.
ng-init="filterSubject="
In some cases filterSubject= gets populated with an id from the query string like ?subject=11
but what do I have to pass from php when the query string is not present
Thank you
Since it looks like you're generating the string in PHP, put single quotes around the filter subject:
ng-init="filterSubject='$subject'"
you can use ternary operator something like this
ng-init="filterSubject = YOUR_EXPRESSION || ''"
You can do something like this :-
<div <?php if($_GET['subject']){ ?>ng-init="filterSubject='<?php echo $_GET['subject']; ?>'" <?php }?>>
.....
</div>
or
<?php
if($_GET['subject']){
$nginit = 'ng-init="filterSubject=\''.$_GET['subject'].'\'"';
}
?>
<div <?php echo $nginit;?>>
.....
</div>

Dynamically set ID in UnderscoreJS template generated using Jade

I'm using Jade to generate JST templates but I'm having trouble setting placeholder for the id field.
.somediv(id=<%= id %>)
...
Jade compiler throws an error for the above syntax
undefined:501
buf.push(attrs({ terse: true, 'id':(<%= id %>), "class": ('somediv')
Is there a way to do this?
Correct syntax for attributes seems to be:
.somediv(id=id)
...
But if you need id to be exactly <%= id %> then you have to quote it and use != for values that shouldn't be escaped
.somediv(id!="<%= id %>")
...

Resources