To replace enter key press event with \n - html

textarea.html
<textarea [(ngModel)]="array" (keypress)="onKeypress($event)"></textarea>
<div>
<p>{{array}}</p>
</div>
textarea.ts
rray:any;
constructor() {
this.array =["test1", "test2", "test3"];
// let array2 = ((array).toString()).split("");
// let array3 = array.join("textarea");
}
ngOnInit() {
}
onKeypress(event){
if (event.key == "Enter"){
this.array = this.array + "\n";
return false;
}
else{
return true;
}
}
}
How to print "\n" when enter key is pressed in the textarea using angular 5? The above code does not work.

actually the error was that I had use "/\n" instead of "\n" as \n is a special character. After doing this it worked

If your code compiles well, then consider adding escape character to show the new line character inline with your textbox area. So instead of "\n" use "\\n".
Here is the working example.

Related

Input Mask for only alpha characters let 1 words only with Primeng in Angular

Like tutorial said "a - Alpha character (defaut: A-Z,a-z)" that's ok.
But when I am applying mask="a" like below it just let me enter 1 word but i dont wanna restrict the size of input.So people can enter any size word to it.
How can i achieve that ?
I tried with characterPattern="[А-Zа-z]" or giving normal html pattern property with regular expresiion like ^[A-Za-z] but didn't work.Thanks in advance
<p-inputMask mask="a" [placeholder]="'gerekli' | translate" [(ngModel)]="User.adi"></p-inputMask>
You can implement the following,
In your component.ts file,
setInputFilter(inputHTML, inputValue) {
[
"input",
"keyup",
"keydown",
"mouseup",
"mousedown",
"select",
"contextmenu",
"drop"
].forEach(function(event) {
inputHTML.addEventListener(event, function() {
if (inputValue(this.value)) {
this.previousValue = this.value;
this.previousSelectionStart = this.selectionStart;
this.previousSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("previousValue")) {
this.value = this.previousValue;
}
});
});
}
Call the function setInputFilter inside AfterViewInit life-cycle hook.
ngAfterViewInit() {
this.setInputFilter(document.getElementById("inputText"), function (value) {
return /^[a-zA-Z]*$/.test(value);
})
}
In your component.html file,
<input id="inputText" pInputText [(ngModel)]="val"/>
I am using InputTextModule of PrimeNG instead of InputMaskModule

Is it possible to select just the colored text in a .json file?

I'm using Brackets to edit a json file with about 1000 lines of code.
I want to extract (copy) just the text in orange... How can I do that? :)
here's a screenshot of the .json file
The orange text is just your text editor. Not idea what editor you're using but on Sublime I'd do a find all on ":" then select all.
Shift + Home key will select end of row (or its shift insert, I'm on a beach atm and can't exactly remember)
With that it will select everything after the ":" which you can copy and cut down from there.
It looks like you want to extract the strings from a nested dictionary.
Leveraging Recursively looping through an object to build a property list you could do:
var myobject = {
aProperty: {
aSetting1: ["asdf","bab"]
},
bProperty: {
bSetting1: {
bPropertySubSetting : true
},
bSetting2: "bString"
},
cProperty: {
cSetting: "cString"
}
}
function iterate(obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (typeof obj[property] == "object") {
iterate(obj[property]);
} else if (typeof obj[property] == "string") {
console.log(obj[property]);
}
}
}
}
iterate(myobject)

How can I remove html tags for parsing the actual value and then put them back?

I am working on highlighting the search result in search difference app and I met some problems.
On the input we get some text inside <pre> tag, that already have some highlighted text using <span> tag.
<ng-container *ngIf="settings?.allowHtmlTransform">
<pre [innerHtml]="row?.value" ></pre>
</ng-container>
My job is to highlight current search result and this is the problem. The row.value I need to parse is something like <div class="NORMAL>Sample <span class="MISSING">Text</span></div>. There are decent amount of highlight classes (ex. MODIFIED, MISSING, EXTRA etc.)
I need to highlight search result (for example "a") but it starts looking inside tags and breaks formatting (for Highlight i use the same <span class="CURRENT">)</span>
The question is how can I parse value without these tags, but when I will return highlighted value they would stay on their place? Maybe there are some beautiful solutions?
It has been 2 weeks since I asked the question and as I got back to work I found solution myself. Maybe anyone find it helpful. So the idea was to split string into parts divided by "<" and ">". And then we can check whether each part is html tag or not and add highlight only to text parts.
So here is the code. There are things to be improved but still it worked well for my case.
class Highlighter {
static hlcolors: Map<IHlType, string> = new Map([
[IHlType.success, 'success'],
[IHlType.highlight, 'currHl']
]);
static getHlVal(value: string, type: IHlType): string {
let clazz = Highlighter.hlcolors.get(type);
return '<span class="' + clazz + '">' + value + '</span>';
}
static hlByPhrase(value: string, type: IHlType, phrase: string): string {
return value.replace(phrase, Highlighter.getHlVal(phrase, type));
}
static parsehl(value: string, type: IHlType, phrase: string){
let temp = [];
let temp1 = value;
while(temp1.length > 0){
let stPos = temp1.indexOf("<");
let enPos = temp1.indexOf(">");
if(stPos === 0){
temp.push(temp1.slice(stPos, enPos+1));
temp1 = temp1.slice(enPos+1);
}
else {
temp.push(temp1.slice(0, stPos));
temp1 = temp1.slice(stPos);
}
}
let res = "";
for(let i = 0; i<temp.length; i++){
if(temp[i].includes("<div") || temp[i].includes("<span") || temp[i].includes("</div") || temp[i].includes("</span"))
res += temp[i];
else res += temp[i].replace(phrase, Highlighter.getHlVal(phrase, type));
}
return res;
}
}

Remove Double Quotes around the String in CSV file

I am using Angular UI-grid to display data in tabular form and i also added a functionality to export the visible data in CSV file but my problem is that in exported file all the string are enclose with double quotes.
Can anyone tell me how to remove those unnecessary double-quotes ?
Any help is appreciated
The behavior that you are referring to comes from the function formatFieldAsCsv(field) within the uiGridExporterService service. There is no API that will allow you to change this with a setting.
What we can do however is use a decorator to override this default behavior without having to modify the ui-grid module itself.
I have demonstrated this in a working plunker.
In the snippet below, I have assigned qualifier to replace the quotations that were initially in use. With this, you can either leave the function as is and have no qualifier at all, or you can change it's value to whatever you like, and that will become the prefix/suffix of each field.
app.config(['$provide', function ($provide) {
$provide.decorator('uiGridExporterService', [
'$delegate',
function myServiceDecorator($delegate) {
$delegate.formatFieldAsCsv = formatFieldAsCsv;
return $delegate;
}
]);
function formatFieldAsCsv(field) {
var qualifier = '';
if (field.value === null) { // we want to catch anything null-ish, hence just == not ===
return '';
}
if (typeof(field.value) === 'number') {
return field.value;
}
if (typeof(field.value) === 'boolean') {
return (field.value ? 'TRUE' : 'FALSE');
}
if (typeof(field.value) === 'string') {
return qualifier + field.value.replace(/"/g, '""') + qualifier;
}
return JSON.stringify(field.value);
}
}]);
http://plnkr.co/edit/8qskcFt7EHSlTQFo4ZUG?p=preview

How can I remove class completely?

I have a class file that has some netstreams and connections and I'm trying to remove the class completely. Here's my code:
function onTestProcessed(e:CustomEvent2):void {
// Remove
rtmp_test.removeEventListener(CustomEvent2.PASS_PARAMS, onTestProcessed);
e.currentTarget.parent.removeChild(e.currentTarget);
// Validation comparison
if (e.boo == false) {
trace("event.boo = ", e.boo);
} else {
trace("event.boo = ", e.boo);
}
}
This code removes the display of video but not its sound. Do I have to find each variable in the class and remove them one by one?
Seems like this solved the problem:
function onTestProcessed(e:CustomEvent2):void {
// Remove
rtmp_test.removeEventListener(CustomEvent2.PASS_PARAMS, onTestProcessed);
rtmp_test.netStreamObj.close();
// rtmp_test.netStreamObj = null;
rtmp_test.vid.clear();
e.currentTarget.parent.removeChild(e.currentTarget);
// Validation comparison
if (e.boo == false) {
trace("event.boo = ", e.boo);
} else {
trace("event.boo = ", e.boo);
}
}
as3 - How to stop video and detach NetStream