Comments (18)
@adamlubek remove 'uirouter/angular' and 'uirouter/angularjs' in your package.json file,
only use 'uirouter/angular-hybrid'
I found this is the working example : https://github.com/ui-router/sample-app-angular-hybrid/tree/e4b1144d5e3e3451f0f0cc640175bb7055294fdd you can try download and build it
from angular-hybrid.
@artaommahe so I changed code from:
const url: UrlService = platformRef.injector.get(UrlService);
url.listen();
url.sync();
to
const url: UrlService = getUIRouter(platformRef.injector).urlService;;
url.listen();
url.sync();
this compiles indeed but it completely breaks routing, states which were working aren't recognized anymore
from angular-hybrid.
@adamlubek also had this problem, this fixed my issue ui-router/sample-app-angular-hybrid#8 (comment)
from angular-hybrid.
@adamlubek i use it like so
deferAndSyncUiRouter(AppMainOldModule);
platformBrowserDynamic()
.bootstrapModule(AppMainModule)
.then(platformRef => bootstrapWithUiRouter(platformRef, AppMainOldModule));
export function deferAndSyncUiRouter(angularjsModule: ng.IModule): void {
angularjsModule
.config([ "$urlServiceProvider", ($urlServiceProvider: UrlRouterProvider) => $urlServiceProvider.deferIntercept()])
.run(["$$angularInjector", $$angularInjector => {
const url: UrlService = getUIRouter($$angularInjector).urlService;
url.listen();
url.sync();
}]);
}
export function bootstrapWithUiRouter(platformRef: NgModuleRef<any>, angularjsModule: ng.IModule): void {
const injector = platformRef.injector;
const upgradeModule = injector.get(UpgradeModule);
upgradeModule.bootstrap(document.body, [ angularjsModule.name ], { strictDi: true });
}
from angular-hybrid.
For anyone coming to this issue looking to resolve the "no provider" errors, make sure that you do not have multiple copies of the @uirouter/*
packages nested in your node_modules directory.
One easy way to find out is to run these commands:
npm list @uirouter/core
npm list @uirouter/angular
npm list @uirouter/angularjs
npm list @uirouter/angular-hybrid
For each one, make sure there is only one version of the uirouter packages in the output.
good output
For example, for @uirouter/core
only version 6.0.1 is listed in the output:
npm list @uirouter/core
[email protected] ~/projects/uirouter/sample-app-angular-hybrid
└─┬ @uirouter/[email protected]
├─┬ @uirouter/[email protected]
│ └── @uirouter/[email protected] deduped
├─┬ @uirouter/[email protected]
│ └── @uirouter/[email protected] deduped
└── @uirouter/[email protected]
bad output
If there are multiple versions of a uirouter library, the output will look something like this:
npm list @uirouter/core
[email protected] ~/projects/uirouter/sample-app-angular-hybrid
├─┬ @uirouter/[email protected]
│ ├─┬ @uirouter/[email protected]
│ │ └── @uirouter/[email protected]
│ ├─┬ @uirouter/[email protected]
│ │ └── @uirouter/[email protected]
│ └── @uirouter/[email protected]
└── @uirouter/[email protected]
Note that versions 6.0.1 and 6.0.3 are both present
note: If you use yarn
package manager, the command is yarn why @uirouter/core
from angular-hybrid.
Remove angular-ui-router (or @uirouter/angularjs) from your package.json and replace it with @uirouter/angular-hybrid. Add the @angular/* dependencies.
I removed those two then working:
@uirouter/angular": "^1.0.0-beta.7"
@uirouter/angularjs": "^1.0.6"
from angular-hybrid.
@leosun1221 I don't understand what you're talking about, Your comment seems incomplete. Which npm package do you mean by angular-ui-router? I've got @angular dependencies added, which exactly are you referencing? Also, I don't have any packages with versions you're referencing ("^1.0.0-beta.7", "^1.0.6").
Your comment isn't too helpful, can you clarify what you meant please?
from angular-hybrid.
I've tried your code @artaommahe , routes are still dead :( the only difference is that I've got "$urlServiceProvider: UrlService" instead of "$urlServiceProvider: UrlRouterProvider" as I don't know where to import UrlRouterProvider from?
I'm running @angular/* version 4.4.2 and angular/cli version 1.4.2 if it makes any difference.
from angular-hybrid.
@leosun1221 I don't have 'uirouter/angular' and 'uirouter/angularjs' in my package.json at all.
from angular-hybrid.
I had the same issue. Appears to be fixed in 3.1.7.
from angular-hybrid.
I had the same issue. Appears to be fixed in 3.1.7.
Hello all, is this still an issue or can I close this? If it is an issue, can somebody show me how to reproduce it?
from angular-hybrid.
I think it was fixed some time ago, I don't face it anymore
from angular-hybrid.
yes, it's all good now, thanks @christopherthielen
from angular-hybrid.
If anyone else is hitting things like this, it has to do with getting the PRECISE dependencies from angular-hybrid. The only thing you want is angular-hybrid, somehow it was not getting uirouter/angularjs and it was causing it to break. I also see it is not working with the latest Angular 5.2, but for now Im going to settle down on 5.1
Unhandled Promise rejection: StaticInjectorError(RootModule)[UrlService]:
StaticInjectorError(Platform: core)[UrlService]:
NullInjectorError: No provider for UrlService! ; Zone: ; Task: Promise.then ; Value: Error: StaticInjectorError(RootModule)[UrlService]:
StaticInjectorError(Platform: core)[UrlService]:
from angular-hybrid.
the example hybrid app works when updated to latest(5.2.3), but I still get this problem on the app I am trying to get working.
from angular-hybrid.
There are complications when using npm linked file:.. local packages and Angular. I am finding that this webpack config fixes it. The key is the modules, it HAS to point all to the TOP node_modules, not a nested version.
` resolve: {
extensions: ['.ts', '.js'],
modules: [
path.resolve(path.join(__dirname, 'node_modules'))
],
symlinks: true,
mainFields: [
"browser",
"module",
"main"
],
alias: {
}
}
from angular-hybrid.
@artaommahe that was a super helpful code snippet.
I modified it to the following:
angular.element(document).ready(() => {
deferAndSyncUiRouter(angularJSAppModule); // angularjs module as a variable
platformBrowserDynamic()
// Manually bootstrap the Angular app
.bootstrapModule(AppModule) // Angular module imported from app.module.ts
.then(platformRef => bootstrapWithUiRouter(platformRef, angularJSAppModule));
});
export function deferAndSyncUiRouter(angularjsModule: ng.IModule): void {
angularjsModule
.config([ "$urlServiceProvider", ($urlService: UrlService) => $urlService.deferIntercept()])
.run(["$$angularInjector", $$angularInjector => {
const url: UrlService = getUIRouter($$angularInjector).urlService;
url.listen();
url.sync();
}]);
}
export function bootstrapWithUiRouter(platformRef: NgModuleRef<any>, angularjsModule: ng.IModule): void {
const injector = platformRef.injector;
const upgradeModule = injector.get(UpgradeModule);
upgradeModule.bootstrap(document.body, [ angularjsModule.name ]);
}
That got everything working for me.
Edit: Also you all may find these imports helpful for the top of your angularjs module file.
import * as angular from 'angular';
import {NgModuleRef} from "@angular/core";
import {getUIRouter} from '@uirouter/angular-hybrid';
import {UrlService} from '@uirouter/angular-hybrid/node_modules/@uirouter/angularjs'
import {UpgradeModule} from "@angular/upgrade/static";
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {AppModule} from "./app.module";
from angular-hybrid.
@AlexSwensen or @artaommahe
Could you tell me please what code should be in AppModule.ts file (Angular module). If I use there code from documentation
const nestedState: NgHybridStateDeclaration = {
url: '/angularRoute',
name: 'angularRoute',
component: UrlTestComponent,
};
@NgModule({
declarations: [
UrlTestComponent,
AngularDowngradeTestComponent
],
exports: [ AngularDowngradeTestComponent ],
entryComponents: [AngularDowngradeTestComponent],
imports: [
BrowserModule,
UpgradeModule,
// UIRouterUpgradeModule.forRoot(),
//UIRouterUpgradeModule.forChild(StaticPagesRoutes)
UIRouterUpgradeModule.forRoot({ states: [nestedState] }),
],
providers: [],
})
export class AppModule
{
constructor(private upgrade: UpgradeModule) { }
ngDoBootstrap() {
setAngularJSGlobal(angular);
this.upgrade.bootstrap(document.body, ['mainApp'], { strictDi: true });
}
}
I have an error 'You try bootstrap application twise'. I think the problem is in
this.upgrade.bootstrap(document.body, ['mainApp'], { strictDi: true });
from angular-hybrid.
Related Issues (20)
- Jest test suite failed to run AngularJS v1.x is not loaded! after upgrade from angular 7 to 9 HOT 6
- How to augment all routes with additional resolve using decorator HOT 2
- ui.router.upgrade' is not available! HOT 1
- Angular 9 - optimization: true breaks build HOT 1
- Version 12 causes "Unknown provider" on Angular states HOT 12
- Upgraded AngularJS component renders itself in ui-view HOT 1
- The target entry-point "@uirouter/angular-hybrid" has missing dependencies HOT 2
- Support for angular12 HOT 5
- UIViewNgUpgrade downgradedModule not specified HOT 1
- ngcc fails
- Angular 14 compatibility HOT 6
- Error bootstrapping AppModule Error: Cannot read properties of undefined (reading 'when') HOT 1
- Failure to inject $transition$ into a downgraded ng2 component HOT 9
- Angular 15 compatibility HOT 3
- After update to 15: UI router error TypeError: this.factory is undefined HOT 19
- random error: Cannot find module '@uirouter/angularjs' or its corresponding type declarations. HOT 3
- Add support for v16 in @uirouter/angular-hybrid HOT 3
- After update to v15.0.2 I get this error "Cannot read properties of undefined (reading 'inherit')"
- Wrong NATIVE_INJECTOR_TOKEN import HOT 2
- Add support for v17 in @uirouter/angular-hybrid HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-hybrid.