-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
ES6: No provider for NavController! (MyApp -> NavController) #5543
Comments
This is intended behavior, as weird as it seems at first. Nav here is a child of MyApp, (specifically a ViewChild, because it's in MyApp's template), which means there is no NavController injector available to MyApp. You can use @ViewChild to access Nav specifically (which extends NavController):
I'm not sure if there's a more Javascript-y way to use ViewChild, as I'm pretty sure the above is TypeScript, but all of the starters use the TypeScript compiler so it will work just fine either way (for more discussion on that see: #5493). Going to close this as it's not a bug, but please feel free to comment if you have any other questions/issues, thanks! |
This seems kind of sketch. What if you just throw a more identifiable exception when someone tries to do this in the @app file. |
@nraboy If I understand @tlancina correctly, this issue is unrelated to @app, but is instead an issue strictly because the NavController is a child of this particular component. If you had done this in an @component or @page you would wind up with the same problem. I definitely feel that the error reported is vague as it seems to be a problem with available providers rather than the instantiation context. An error indicating the trouble is as a result of attempting to access a ViewChild through injection would be considerably more helpful. While I think the intuitive approach for attempting to access this component is through injection, the ViewChild decorator seems to be in line with Angular2's design approach and is reasonably well documented by Angular2 here. Currently I believe the most useful thing that could be done to handle these sorts of issues would be to provide better documentation, especially regarding the Nav Controller. Several recent issues posted on the Ionic Forums seem to be related to the subject, which implies a lack of understanding by the community for this feature. |
+1 on documentation |
I got the error message:
at @ViewChild(Nav) nav; |
I think in app.js, you can just do the following to get a handle to the NavController, where this.app is reference to App |
Thanks for the feedback everyone, this was not a well documented case, so I've updated the docs on using When I originally answered I thought |
Should be somewhere in big bold red letters. Hours of googling finally did some good |
Scenario - I have implemented push notifications in ionic2. On getting notification and clicking on it, i want to redirect to different pages based on the additional data that comes from the server. I tried writing a separate component with @page decorator with no template in it. `import {Injectable} from 'angular2/core';
|
I made it work using : |
Here is where I found the solution. |
Forced that shit to work with getter and Injector
|
Here is solution to get nav controller in any provider
I use this approach to detect unauthorized response from server in myAuthHttp which is Http wrapper (this wraper is used in all app instead standard Http and allow to send PUT/GET/POST/DELETE request with authentication token which expires after some time). But better solution will be to raise some 'event' from this provider and UI should detect it and go to login page - but how to do it? |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Short description of the problem:
NavController not injecting in the latest beta.
What behavior are you expecting?
NavController to inject in the constructor method
Steps to reproduce:
In the app/app.js file add the following code:
Ionic Version: 2.x
Run
ionic info
from terminal/cmd prompt:The text was updated successfully, but these errors were encountered: