-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(positioning): angular 2.2 modal.show is throwing issue #986
Comments
Forget about directives, use exported modules |
We need to update docs... fast ;( |
Thanks for your help, I am now running ng2-bootstrap@1.1.0. So I now have a shared module which contains all of the bootstrap modules I am using in the app.
Here is my app.module.ts:
For some reason, the error "Token must be defined" still shows up when trying to show a modal and I am not using directives anymore. |
@escarabin is this still an issue in v1.1.5? |
No reaction -> close... |
Can you please provide the current HTML-Template, the related component and your ngModule code? |
http://bit.ly/ng2-bootstrap-plnkr |
I don't get it. It is working in my Plunkr... https://plnkr.co/edit/qFzk0ysRQwbg7vvrkN44?p=preview I am going to investigate more into my code and get back to you if I find any solution. |
I updated to v1.1.6 tough. The error has now changed to "applicationRef instance not found" when I try to open a modal. |
How do you bootstrap your application? |
I have a boot.ts file that looks like this:
And it is loaded by systemJS inside my HTML head tag :
|
can you try to import ng2 bs like this: https://github.com/valor-software/angular2-quickstart/blob/master/index.html#L16 and compare your system.js config to sample one? |
I just tried what you suggest and and got same result. Actually I also tried to show up a modal inside components of my app.module.ts and it worked. The issue seems to happen only inside component of child modules. In all of my child modules. |
sorry, but without reproduce sample, I will not be able to help you :( |
In other systemjs issues the problem was: |
@escarabin is your problem solved? Can I close this issue? |
Sorry but it is not solved actually. I will be working on a fix today and will let you know if I find something, it might be useful for others. |
Just wanted to verify https://github.com/escarabin. Facing a similar error message with ng2-bootstrap version 1.1.12 the moment I try to invoke:
Works fine when loaded in the browser, but fails when executed in a test run by karma. The interesting thing is: Running the following while testing does not lead to any errors: |
Hey @JFMueller! But I also confirm that I am not encountering any issues with using I will try to include EDIT : I am using v1.1.6 though. I don't think you should be using EDIT : After some testing, I am getting the same error when launching |
@JFMueller I am using v1.1.14 and getting the same error |
Hi, I am also seeing the same issue. It seems to be a timing issue. When I do the following:
Then I get the below error:
It seems that there are no components registered in |
I have the above issue (applicationref instance not found); but mine is triggered from a click function. |
ng2 v2.2 added a breaking change to internals working on it |
@valorkin It will be very appreciated |
Looking forward to this! |
So after talking to @valorkin he let me know that the answer (for now) is at the very top of this thread. I just failed at reading the entire thing lol. Add the following to your constructor.
And add the following to your imports
|
and if your had |
ok, guys new injection service is working ;) |
ya same issue, can't get modal to work... |
working on it, in a while you can check how popovers look like inside ;) |
While the given workaround did not fix the issue, here is the version that works for me. import { Component, ViewContainerRef } from '@angular/core';
import { ComponentsHelper } from 'ng2-bootstrap/ng2-bootstrap';
ComponentsHelper.prototype.getRootViewContainerRef = function () {
// https://github.com/angular/angular/issues/9293
if (this.root) {
return this.root;
}
var comps = this.applicationRef.components;
if (!comps.length) {
throw new Error("ApplicationRef instance not found");
}
try {
/* one more ugly hack, read issue above for details */
var rootComponent = this.applicationRef._rootComponents[0];
//this.root = rootComponent._hostElement.vcRef;
this.root = rootComponent._component.viewContainerRef;
return this.root;
}
catch (e) {
throw new Error("ApplicationRef instance not found");
}
};
@Component({
selector: '......',
template: "......"
})
export class AppComponent {
// As instructed at http://valor-software.com/ng2-bootstrap/#/modals
private viewContainerRef: ViewContainerRef;
public constructor(viewContainerRef: ViewContainerRef) {
// You need this small hack in order to catch application root view container ref
this.viewContainerRef = viewContainerRef;
}
} |
@valorkin will you add some comments on #986 (comment) please? This injection is really weird, especially if one wants to ship the modals within another module; I need to force people to make this injection in their project just because... Because what? |
There are v1.1.16-7 |
Pay attention to forRoot |
Works with v1.1.16-7 :-) |
@valorkin I tried installing v1.1.16-7 and am getting 404's for component-loader.js and positioning.js. I am using systemjs. Does this work with systemjs or do I need to switch to webpack/CLI? |
NVM I got it working. Had to add .forRoot() to every imported ng2-bootstrap module. And then had to change systemjs like so: from |
@crh225 you know that such words can harm? please don't write such things |
ng4 will be released in march |
@valorkin Thanks for your time on this project it is very helpful to have this module! Keep up the good work! |
@conor-mac-aoidh thank you! ;) |
@valorkin @conor-mac-aoidh usually +1 is not the best thing to do but I cannot avoid it. Thank you for your contribution to the development of angular2 and its community 👍 ! I believe this project helps lots of people and makes angular2 closer to the not experienced users. Don't listen to the ugly people, listen to the good ones :) |
same here, amazing job and THANKS for the effort, sure is appreciated!! |
Thanks you so much ;) |
@valorkin This issue still persists during runtime of AoT build when I add bsModal div and use shared module to include 'ng2-bootstrap' modules.
I use Angular 2.4.1, ng2-bootstrap 1.1.16-11 Here is a repo with steps to reproduce: Not sure if it's systemjs-specific issue. Apologize in advance if so =) |
I use the workaround as described at the top and it worked wel using angular 2.4.3 and ng2-bootstrap v1.1.16. After upgrade to ng2-bootstrap V1.2.1 it breaks and complains that the componentshelper is not exported anymore. The ng2-bootstrap document states that this component is removed. |
@TyGp we had this very same issue yesterday. i cloned our repo on another machine and ran However, we ran quickly into two other breaking changes.
Most of this stuff is mentioned on the project page. It was our mistake to leave ourselves open to breaking changes via the |
This is broken in angular 4 again, and now EDIT: nm, figured it out, I need to add |
Angular v2.2 broke our get root view component ref hack
temporary workaround:
ComponentsHelper
toAppModule
(root module)AppComponent
(root component)I am facing an issue with my ng2-bootstrap modals. For some reason, I am not able to show them.
Here is my HTML :
Here is my NgModule:
I see this error in the log console :
Error: Uncaught (in promise): Token must be defined!
and the modal does not show up
I am running Angular 2 RC5.
Is there something I am missing here?
The text was updated successfully, but these errors were encountered: