I have a text, in which there are inputs. These inputs were provided by Pipe (I needed to replace some words with these inputs). Now I want to write in each input different words, and store it to obj, so if I type in first 3 inputs smth like red, green, apple it stores to object { "0": "red", "1": "green", "2": "apple", }
Here is code
Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({name: 'replacer'})
export class SanitizeHtml implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(data, arg) {
arg.forEach(item => data = data.replace(new RegExp(item, 'g'), '<input type="text" >'));
return this.sanitizer.bypassSecurityTrustHtml(data);
}
}
I Guess I need to hang something on this input in pipe, like
<input type="text" name="{{i}}" ngModel #prix="ngModel" [id]="i">
But it doesn't work now...
My component is
@Component({
moduleId: module.id,
selector: 'part2',
template: `
<p>{{values}}</p>
<p>{{abc}}</p>
<div [innerHtml]="itemsSource | replacer: abc"></div>
<button>Ok</button>
<p>Score <input/></p>
<pre>{{f.value | json}}</pre>
`,
providers: [DataService]
})
// @Pipe({name: 'replacer'})
export class Part2Component implements OnInit {
@ViewChildren ('prix') inputs;
public itemsSource: string;
public abc: string[];
constructor(public dataService: DataService) {
}
ngOnInit() {
this.abc = this.dataService.getData3();
this.itemsSource = this.dataService.getData2();
}
}
I use data from Dataservice
import { Injectable } from '@angular/core';
@Injectable()
export class DataService {
getData2() {
let items3: string = 'I like orange, blue, black, pink, rose, yellow, white, black';
return items3;
}
getData3(){
let items4: string[] = ['black', 'yellow'];
return items4;
}
}
So, now I have Picture this example, and I want be able to type in words and display as object Picture 2 {"0": "APPLES", "1": "GREEN", "2": "BROWN",}
Please, help me...