3

I am trying to populate table for which code is generated from the api with input and the formulas to calculate and display in other input which is working perfectly in angular 1.2 with .net core, I want to do same in angular 4 in there any solution. I tried following code but it's inserting as string. Let me be more specific, i have some master from which dynamic table has to be created which should look like Excel and one col will have Main Master like Name,department,designation grade against 12 col will be created for 12 months under months again there is some masters like basic salary, allowance, TA/ DA, other Allowance , PF like that for every month, every row at end of the month should calculate the sum, every grade should have total and every department should have total. so for the same all html code is getting generated from the back end which should append to front end from ajax and all calculation should work. i am able to achieve same with angular 1.2 but want to achieve the same with angular 4

@ViewChild('abcd') 
private abcd: ElementRef;

constructor(private renderer: Renderer2) {
}

onClick() {
        const li = this.renderer.createElement('li');
        const text = this.renderer.createText('Click here to add li');
        this.renderer.appendChild(li, text);
        this.renderer.appendChild(this.abcd.nativeElement, li);
}

but not getting result, in angular 1.2 i am achieving the same with just

$('#xxx').append($compile(json)($scope));
$scope.$apply();
Avinash A R
  • 176
  • 2
  • 10
  • why would you use jquery even in angular 1.2 ? Why not use `ng-repeat` in angularjs 1.2 and right now in angular 4 why not use `*ngFor` ? Using jquery or even `renderer` of angular defeat's angular's purpose. – Dhyey Jan 04 '18 at 14:26
  • I'm not sending json for table, I am generating HTML code for table from back end – Avinash A R Jan 04 '18 at 14:29
  • checkout https://stackoverflow.com/questions/34784778/equivalent-of-compile-in-angular-2 – Dhyey Jan 04 '18 at 14:32
  • i have tried that but it wont help as it is just appending as string – Avinash A R Jan 05 '18 at 05:48
  • Did you try this [answer](https://stackoverflow.com/a/44713107/) for angular 4 ? If you are willing to upgrade to angular 5 you can use [Dynamic component loader](https://angular.io/guide/dynamic-component-loader) which I think is easier to implement – Dhyey Jan 05 '18 at 06:36

0 Answers0