Merge divs with same value from angular [closed] - html

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to make a Calendar of my own
https://stackblitz.com/edit/angular-1kfbod?file=src/app/app.component.css
This is a full example of my component.
How can I merge the week divs that have the same value {{day.weekNumber}} (one div instead of 4 for the example below)?

In your case, you should have separate array for your week numbers.
Typescript
public weekNumbers: number[] = [];
public rowWidth: any = 100 + '%';
ngOnInit() {
...
... // your existing code
...
let weeks = [];
for (let i = 1; i <= this.numberOfDaysCurrentMonth; i++) {
this.daysToDisplayInCurrentMonth[i - 1] = new Date(this.currentYear, this.currentMonth - 1, i).getDay();
const day = {
number: i,
weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
name: this.dayNames[this.daysToDisplayInCurrentMonth[i - 1]],
weekNumber: this.getWeekNumber(new Date(this.currentYear, this.currentMonth - 1, i))
};
weeks.push(day.weekNumber);
this.days.push(day);
}
this.weekNumbers = [];
weeks.forEach((ele) => {
if(this.weekNumbers.indexOf(ele) < 0) {
this.weekNumbers.push(ele);
}
});
this.rowWidth = (100/this.weekNumbers.length) + '%';
}
HTML
<div class="row-calendar">
<div class="week-number" [style.width]="rowWidth" *ngFor="let week of weekNumbers">
<label class="number-label"><span>{{week}} </span></label>
</div>
</div>

Related

Check if a string contains a value from an array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What I'm trying to do is conditionally display a div based on user input. I'd like to parse through the input and if it contains somewhere within it (The input could be a whole paragraph) one of several keywords that are in an array, then it will return true and display the div. This is what I have so far:
jQuery(function($) {
$(".conditional-content-container").hide());
var user_input = $(":input[name=input_4]");
user_input.change(function() {
if (user_input.val().indexOf(["hello", "world", "foo"]) !== -1) {
$(".conditional-content-container").show();
} else {
$(".conditional-content-container").hide();
}
});
});
<div class="conditional-content-container">
Content to be displayed if user input contains the words "hello" or "world" or "foo" somewhere within it
</div>
You need to loop over the array and check if they exist in the string
var words = ['apple', 'foo', 'bar']
function hasAnyWords(str) {
return words.some(word => str.indexOf(word) > -1);
// return words.some(function(word){
// return str.indexOf(word) > -1;
//});
}
function hasAllWords(str) {
return words.every(word => str.indexOf(word) > -1);
// return words.every(function(word){
// return str.indexOf(word) > -1;
//});
}
console.log(hasAnyWords('I like an apple'));
console.log(hasAnyWords('I like a pear'));
console.log(hasAllWords('I like an apple'));
console.log(hasAllWords('I like a bar foo apple'));

Rails: style a number_to_currency with HTML <sup> Tag [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Inside a rails app I have this <%= number_to_currency product.price %> which gives this html output: $29.98.
Is there a way I can style the above number_to_currency html output in order to look like the following?
<p><sup>$</sup>29<sup>98</sup></p>
I have created a small example using JS.
let symbol = pricePara.innerText.split("")[0];
let price = pricePara.innerText.split(".");
let priceLHS = price[0].replace(symbol, "");
let priceRHS = price[1];
pricePara.innerHTML = "<sup>" + symbol + "</sup>" + priceLHS + "<sup>" + priceRHS + "</sup>"
p{
font-size:3em;
}
<p id="pricePara">$29.98</p>
With multiple items.
const priceParas = document.querySelectorAll('.price');
priceParas.forEach(function(item) {
let symbol = item.innerText.split("")[0];
let price = item.innerText.split(".");
let priceLHS = price[0].replace(symbol, "");
let priceRHS = price[1];
item.innerHTML = "<sup>" + symbol + "</sup>" + priceLHS + "<sup>" + priceRHS + "</sup>"
})
p {
font-size: 3em;
}
<p class="price">$29.98</p>
<p class="price">$2934.983</p>
<p class="price">$29434.00398</p>

Angular2 how to display an array of numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Whats is the most elegant solution in angular2 for displaying an html table of z numbers in x rows and y columns?
X, Y and Z are numbers not necessarily collections. Also the table should contain numbers 1 to z.
I would do it like this : Plunker
Component
rows : any[];
cols : any[];
constructor() {
this.rows = Array(50).fill('');
this.cols = Array(10).fill('');
}
Template :
<table>
<tr *ngFor="let row of rows; let rowId = index">
<td *ngFor="let col of cols; let colId = index">{{rowId + colId*10+1}}</td>
</tr>
</table>

How to find out colour of placeholder? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I know how to set colour of placeholder, but what if I need to find out what's colour of placeholder on some page? I cannot find this property with Chrome Devtools. ColorZilla doesn't help either.
It seems you can't access the pseudo placeholder attribute's CSS in DevTools. You can only get the text value using getAttribute('placeholder') in JavaScript.
However, it is possible to view the style properties using JavaScript instead of manually finding them in the CSS files. This is not ideal, but I created a general purpose function that allows you to specify the selector (or part of the selector), and the attribute you are looking for, and it will loop through all the stylesheets and log a table to the console.
function getSelectorStyle(selector, attribute) {
var rules = [];
function CSSRule(sheet, selector, value) {
this.sheet = sheet;
this.selector = selector;
this.value = value;
}
var styleSheets = document.styleSheets;
for (var i = 0; i < styleSheets.length; i++) {
var currentSheet = document.styleSheets[i];
if (currentSheet != null) {
var ruleList = currentSheet.cssRules;
if (ruleList != null) {
for (var j = 0; j < ruleList.length; j++) {
var currentRule = ruleList[j];
if (currentRule.selectorText != null) {
if (currentRule.selectorText.indexOf(selector) != -1) {
var sheetLocation = currentSheet.href ? currentSheet.href : "inline-css";
var item = new CSSRule(sheetLocation, currentRule.selectorText, currentRule.style[attribute]);
rules.push(item);
}
}
}
}
}
}
console.table(rules)
}
getSelectorStyle("placeholder", "color");
Update:
In terms of your problem with the colour not matching with the Amazon site, as per the comments below, it appears that the selector .form-control::-webkit-input-placeholder is not applied. The input field isn't contained in form-control. The default placeholder colour is applied instead, which is #A9A9A9 (in Chrome at least), which is what you are seeing.

Javascript - Populate country code drop down onChange of country dropdown [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Is there any Javascript plugin to populate country codes on change of country dropdown?
Plug-ins, not that I know of... I know answers shouldn't only include external links, but I guess this might be exception, I will include a few links in case 1 breaks one day...
Since Country names and codes don't change too often nowadays might be safe with this text extract:
http://www.textfixer.com/resources/dropdowns/country-list-iso-codes.txt
then using split(':') function, easy populate text & value of select lists
options elements like this:
function populateCountriesDropDown() {
var file = "countries.txt";
var selectList = document.getElementById('selectID');
var rawlist;
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
rawlist = rawFile.responseText.split('\n');
}
}
}
rawFile.send(null);
for (var i = 0; i < rawlist.length; i++) {
var country = rawlist[i].split(':');
selectList.options[selectList.options.length] = new Option(country[1], country[0]);
}
}
OR other links with what you might be looking for:
http://www.freeformatter.com/iso-country-list-html-select.html
https://github.com/umpirsky/country-list