How solved the sintax to concat an element HTML? - reactjs

I have a code to render my value
<div >{`${t('single:yes')}: ${value}`}</div>
but i need to put a span between the value, for example:
<div >{`${t('single:yes')}:<span> ${value}<span>`}</div>
but dont work, what is the wrong?

I think u want the code show like this?
before
<div >{`${t('single:yes')}:<span> ${value}<span>`}</div>
after
<div >{t('single:yes')}:<span> {value}</span></div>

Related

Find Codeception first elements with more than one CSS class with same name

I have something like the following markup:
<div class="test">
<div class="test2">test</div>
<div class="test2">test2</div>
<div class="test2">test3</div>
<div class="test2">test4</div>
</div
I want to click the first test2 class
Check this cheatsheet, it explains how to get the first element of an html tag : https://devhints.io/xpath
$I->click('(//div[#class="test2"])[1]');
This code should work, just try it here : https://extendsclass.com/xpath-tester.html
Maybe something like this
.test .test2:nth-child(1)

How to bind HTML to an Element - AngularJS

I am trying to bind html to my div element, but dont really know how to do it. I am not great with angularjs, but should ng-bind-html do the trick?
This is how I tried to do it,
<div ng-bind-html="{{tile.Info.Title}}"></div>
<div ng-bind-html="{{tile.Info.Content}}"></div>
In angular 2 its just [innerHTML], cant get it to work here, any suggestion?
You can get an example here.
<div ng-controller="ExampleController">
<p ng-bind-html="myHTML"></p>
</div>
As also suggested in comments by #Aleksey when you are using ng- there is no need to use curly brackets {}. So your code should be like:
<div ng-bind-html="tile.Info.Title"></div>
<div ng-bind-html="tile.Info.Content"></div>

ng-switch-when and ng-class compatibility

I was wondering if there were no compatibility issues when ng-switch-when and ng-class are using on the same element like in this sample.
I'm trying to dynamically change the class of this four elements but for some reasons this isn't working on all of them, just on the one who's currently displayed.
Does anyone know what's going on here?
<div>
<div ng-switch="sw" ng-init="sw=1">
<div ng-switch-when="1" ng-class="oneClassOrAnother()"></div>
<div ng-switch-when="2" ng-class="oneClassOrAnother()"></div>
<div ng-switch-when="3" ng-class="oneClassOrAnother()"></div>
<div ng-switch-when="4" ng-class="oneClassOrAnother()"></div>
</div>
<div>
<button ng-click="goTo(1)">1</button>
<button ng-click="goTo(2)">2</button>
<button ng-click="goTo(3)">3</button>
<button ng-click="goTo(4)">4</button>
</div>
</div>
Switch between divs.
$scope.goTo = function(x) {
$scope.sw = x;
}
Return one class or the other one.
$scope.oneClassOrAnother= function() {
if (...) return "class1";
else return "class2";
}
Many thanks.
It doesn't look like you're using the ng-class syntax correctly. Try something like this:
<div ng-class="{class1: oneClassOrAnother()}" ng-switch-when="1">1</div>
Where oneClassOrAnother() returns either true or false and "class1" is the name of the class.
Here's a working example of using ng-class and ng-switch-when together: http://plnkr.co/edit/n86SKEktRcPnBy05o8eZ?p=preview
Angular ngClass docs: https://docs.angularjs.org/api/ng/directive/ngClass
I think its all fine with your code, look at this plunk, I reproduced it and its working. Compare this to your code, maybe you have forgotten about controller?
http://plnkr.co/edit/Lz7L3S?p=preview
Only difference i guess is the fact, that I initiated sw from controller, not from view.
<div ng-switch on="sw">

Wrapping Element with multiple nested transclude

This seems like such a simple thing, but I am just not able to wrap my head around how to do it.
Here is what I want:
<my-card>
<my-profile>
<my-address>101 Some St.</my-address>
<my-phone>555-555-5555</my-phone>
<my-description>I have a great profile</mydescription>
</my-profile>
<my-option doclick="Option(1)">Do One</my-option>
<my-option doclick="Option(2)">Do Two</my-option>
</my-card>
That turns into something like this:
<div class="card">
<div class="profile">
<div class="Address">101 Some St.</div>
<div class="Phone">555-555-5555</div>
<div class="Description">I have a great profile.</div>
</div>
</div>
I'm not sure what your data look like, but you simply use Angular tokens in your directive:
<my-card>
<my-profile>
<my-address>{{user.address}}</my-address>
<my-phone>{{user.phone}}</my-phone>
<my-description>{{user.description}}</mydescription>
</my-profile>
<my-option doclick="Option(1)">Do One</my-option>
<my-option doclick="Option(2)">Do Two</my-option>
</my-card>

How can I bind a parameter inside of ng-click?

The best way to explain what I'm trying to do is to just show you an example. Here is the code I have:
<div ng-click="doSomething('path/to/script/with/{{parameter}}')">Click Here</div>
<div>Parameter is {{parameter}}</div> // I can see parameter here
The problem is that {{parameter}} is not binding to the ng-click. I can manually enter the parameter (e.g., '12') and the ng-click works fine, but I don't want to set it manually.
I have tried the following, but none of them work:
<div ng-click="doSomething('path/to/script/with/parameter')">Click Here</div>
<div ng-click="doSomething('path/to/script/with/'parameter)">Click Here</div>
Any ideas?
try
<div ng-click="doSomething('path/to/script/with/' + {{parameter}})">Click Here</div>
or
<div ng-click="doSomething('path/to/script/with/' + parameter)">Click Here</div>
or just read them from scope in your function.

Resources