I am trying to use templates with Angular2 and it is not working as expected. Here is what I have tried so far. Does anyone have any ideas or maybe another way that I could approach it?
First of all, I am using MEAN stack that express generates an index.html, nodejs creates the templates and angular is the app.
index.html
{includes header.tpl}
<scripts> ... </scripts>
<my-app> Loading AppComponent content here ...</my-app>
{includes footer.tpl}
Inside my header.tpl I have some directives that I would like angular app interpret them
header.tpl
<html>
<header> ... </header>
<body>
<div *ngIf='user.status === "new" '> ADDED THIS </div>
...
app.component.ts
import { Component, Inject } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
@Component({
moduleId: module.id,
selector: 'my-app',
template: `<h1>Hello</h1> <div *ngIf='user.status === "new"'> ADDED THIS 2 </div>`,
})
export class AppComponent {
public user:any = {};
constructor(@Inject(ActivatedRoute) public activatedRoute: ActivatedRoute) {
this.checkParams();
}
private checkParams() {
this.activatedRoute.queryParams.subscribe((params: Params) => {
if (!!params['status'] && params['status'] === 'new') {
this.user.status = 'new';
console.log('I am new');
} else {
console.log('I am NOT new');
this.user.status = 'old';
}
console.log('user', this.user);
});
}
}
When I access my application by
domain.com?status=new
only shows 'ADDED THIS 2', but I also want to show 'ADDED THIS'. As you can see, 'ADDED THIS 2' is running inside <my-app>
and 'ADDED THIS' outside.
So any idea? Thank you.