Hi !
I begining to learn Angular2. I have succeeded to add a component on the
fly.
This component it's a popup which is used to login. I have a button close.
When i clicking on it I succeed to close my login compnent.
For to do this I use this code:
(<any>window)._components.forEach(function(compo){
if (compo.componentType.name === "LoginComponent") {
console.log(compo);
compo.dispose();
}
});
But the dispos() function remove my login-window div and i want to remove
only the content of this div.
It's a problem for me because when i click on Login button this
login-window div doesn't existe.
Someone can help me and explain me how can I remove and add a component
correctely ?
this is my app.component.ts :
import {Component} from 'angular2/core';
import {DynamicComponentLoader} from 'angular2/src/core/linker';
import {Injector} from 'angular2/core';
import {LoginComponent} from './login/login';
@Component({
selector: 'my-app',
templateUrl: 'app/core/main-page.html'
})
export class AppComponent {
public logo = "heritage.png";
constructor(private dcl: DynamicComponentLoader, private injector:
Injector) {}
clicked(event, target) {
event.preventDefault();
if (target === "login") {
this.dcl.loadAsRoot(LoginComponent, '#login-window',
this.injector).then((ref) => {
document.querySelector("#login-window").classList.toggle("hide");
(<any>window)._components.push(ref);
console.log((<any>window)._components);
});
}
}
}
And this is my LoginComponent:
import {Component} from 'angular2/core';
@Component({
templateUrl: 'app/login/login.html',
})
export class LoginComponent {
clicked(event, target) {
event.preventDefault();
if (target === "login-close") {
(<any>window)._components.forEach(function(compo){
if (compo.componentType.name === "LoginComponent") {
console.log(compo);
compo.dispose();
}
});
}
}
}
and this is my main-page.html:
<div id="main-content">
<header>
<div id="logo">
<img src="../../src/imgs/{{logo}}" alt="">
</div>
<button class="mdl-button mdl-js-button mdl-button--raised
mdl-js-ripple-effect mdl-button--accent" (click)="clicked($event, 'login')">
LOGIN
</button>
</header>
<div id="login-window" class="hide"></div>
<footer>
<span>© 2016-2017 Heritage team</span>
</footer>
</div>
Best regards !
Nicolas
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.