import {Page, NavController} from 'ionic-framework/ionic';
@Page({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
constructor(nav: NavController){
}
}
and I’m getting the following error.
Error: Cannot resolve all parameters for 'HomePage'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'HomePage' is decorated with Injectable.
at NoAnnotationError.BaseException [as constructor]
I’ve had a look on the FAQ, ionic NavController example and the documentation. But I cannot spot an error on why its complaining. For me it seems like Im importing everything correctly.
What I could be doing wrong, thanks in advance
cheers,
Sam
Below are my system info
Your system information:
Cordova CLI: 5.4.1
Gulp version: CLI version 3.9.0
Gulp local:
Ionic Version: 2.0.0-beta.1
Ionic CLI Version: 2.0.0-beta.17
Ionic App Lib Version: 2.0.0-beta.8
ios-deploy version: Not installed
ios-sim version: 5.0.2
OS: Mac OS X El Capitan
Node Version: v4.1.1
Xcode version: Xcode 7.0.1 Build version 7A1001
Your build does not appear to be recognizing the NavController as a provider. You could add a reference to it in the providers list like this, but it may wind up giving you a new NavController or may need additional providers to create.
I’m not sure when the NavController is normally added to the provider list, but it appears to be sometime after the initial app load, so I’d be cautious using the above.
Another option is you can grab the NavController from the IonicApp class like this:
Which part is incorrect? I’ve had the same problem in my Typescript build, and this was the fix used to work around it. Adding NavController to the @App required providers which were unspecified. The app.getComponent(
‘nav’) workaround I mentioned works beautifully in a production app currently.
What am I overlooking with my current implementation?
EXCEPTION: No provider for NavController! (MyApp → SomeService-> NavController)BrowserDomAdapter.logError @ app.bundle.js:32184
app.bundle.js:32184 STACKTRACE:BrowserDomAdapter.logError @ app.bundle.js:32184
app.bundle.js:32184 Error: DI Exception
at NoProviderError.BaseException [as constructor] (app.bundle.js:7840)
at NoProviderError.AbstractProviderError [as constructor] (app.bundle.js:8536)
at new NoProviderError (app.bundle.js:8572)
at Injector._throwOrNull (app.bundle.js:6894)
at Injector._getByKeyDefault (app.bundle.js:6945)
at Injector._getByKey (app.bundle.js:6885)
at Injector._getByDependency (app.bundle.js:6871)
at Injector._instantiate (app.bundle.js:6764)
at Injector._instantiateProvider (app.bundle.js:6754)
at Injector._new (app.bundle.js:6743)
This is being injected in the constructor for the top level application class (@App). When using the approach I suggested earlier, I have no problem whatsoever. What would you propose that I have done wrong to generate this problem?
note: For version control purpose we are developing with “ionic-framework”: “2.0.0-alpha.53”, “angular2”: “2.0.0-beta.1”,
Very interesting! Does that NavController let you push things to it? Usually NavController providers are instantiated because somewhere there is an ancestor component that extends NavController, like a Nav or a Tab or Tabs.
Conceptually I’m not sure how a NavController that isn’t associated with some sort of component would work, because where are things being pushed to?
From a technical standpoint, I’m not sure how that could be working, because it doesn’t look like NavController is Injectable (in the beta.2 or in alpha.53), so angular would have no way of knowing to provide its dependencies.
Also, NavController has an ElementRef as part of its constructor, which I would think would fail if it were in the providers array and not coming from a component.
But! I believe you that the code is working, so I’m genuinely curious what’s going on here. What is your use case? If it’s related, could you weigh in on https://github.com/driftyco/ionic/issues/5543? Navigation is something where I think we want to better understand how people expect it to be working, so we make sure it’s easy to do or document the common points of confusion really well. Thanks!
This is the element that is getting consumed by the getComponent reference. We had obtained this code, I believe, from an early sample app that was provided. I could not find reference to the initial project, but this is the current code given by the menu docs provided here. The current use case for the code I posted previously is similar. We have a service that will return a user to the landing page under certain conditions.
As a followup to this problem, I scanned through the source code for app.ts, as it seems we’ve probably been abusing it, and noticed that many of the methods in this class are commented as private, but the private keyword is not utilized. Is this intentional? With the way that the previously linked menu docs were written, it seems to imply that at least this method is intended to be used as public, though the code comments imply this is misuse. At the very least this causes some confusion regarding best practices.
So to summarize-
I was unaware about how some of our features were fully implemented and left out a major detail about the directive in the app.html. This likely caused the rest of the above to work. I do find it interesting that I’d need to go through the HTML side of things to grab the nav in my implementation.
constructor(
public navCtrl: NavController,
public googleplus: GooglePlus,
public alertCtrl:AlertController,
private platform:Platform,
public auth:Auth,
public user:User){ }
still it shows can’t resolve for all paramaters for Auth?
The error message was the same as this thread’s question. I was able to resolve it. I was importing and using ‘App’ inside of a @injectable provider that was the cause. My guess is probably a cyclic dependency was established somewhere…