-
Notifications
You must be signed in to change notification settings - Fork 15
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
How to Install on Ng1 #4
Comments
I am running into the same issue. I just upgraded to 1.0.0-rc.1 from 0.3.x and reworked a lot of my application in the process, primarily in order to be able to take advantage of sticky states, but it's not clear how to configure them. Any advice would be much appreciated! |
I know that this is an issue today. I'll write up some instructions when I get back from vacation. |
Thank you Chris. In the meanwhile i tried to compile by myself the .ts files... After Can we get a quick advice on how to proceed to obtain a single js file to be referenced in html file via |
Sticky states imports ui-router-core but angular-ui-router doesn't have that. If using UMD bundles, we will need a shim that re-exposes angular-ui-router as ui-router-core. Then you can get the window['ui-router-sticky-states'] and find the plugin class to register with the router |
I tried the howto at the end of the page https://ui-router.github.io/ng1/ but with ui-router-core and sticky-states instead of angular-ui-router. Is this attempt totally random? |
I am also caught in between upgrading to ui-router 1.0.0-beta.3 and wanting a sticky states feature, but this port (of the sticky states feature on the legacy ui-router) is not providing a simple js release file. @christopherthielen, can you please provide one? |
Hi all (@witoldszpur, @hinet2013), I ended up writing a migration of the typescript code to js, which works for me. The code can be found here: Hopefully this helps you :) |
is porting from TS to JS the only option at this point? |
Hi Chris, what do you mean with
I tried to mimic the way the Visualizer bundle is generated ` cd .. #Building Visualizer plugin from sources: the bundle built by me works in my application... cd .. git clone --branch 1.2.0 https://github.com/ui-router/sticky-states.git //1 - Edited package.json to add 'bundle' commands ispired by Visualizer plugin npm install I was able to load the plugin at config time and get the StickyStatesPlugin instance but it crashes in attempting to use some 'core' API (seems that he uses a bundled copy of it instead of the one provided by anular-ui-router) Can you provide some hints? PS. the solution proposed by dsills22 based on decoration approach does not worked for me.. |
@Aduer, I updated with a plunker in case it might help you or others: http://plnkr.co/edit/JD9fEVnjvFMJmnmRIM2v?p=preview |
Thank you @dsills22 . Your solution works in general, but i encounter a crash when a redirect happens with options 'reload: true'
|
@dsills22 Thank you so much for your work on this! Has anyone gotten this to work with modals? I want modals to pop up via deep linking, with a default view in a different state/view. For example, a dashboard. |
After recent updates by the author no more workaround are required!
With this stuff i got the full-functionality on Angular 1 with plain JS, so in my point of view this issue can be closed edit by cthielen: do not use |
@Aduer, thank you for posting these steps! It would be very helpful if these steps were documented with explicit examples somewhere in the documentation for getting started in this repo/project before the issue is closed. 😅 |
@pamo In order to use sticky-states you need to make it running beside the ui-router-core host. In case your application already uses a bundle that includes the angular 1 stuff+core you have to replace that bundle with a ui-router-core 'standalone' pluginhost and a angular 1 plugin, otherwise you will end up with two instances of the ui-router-core running in your app. The angular 1 router plugin is already available on bower and i used that. The other components (core & sticky state) are not availabe so you have to build them from sources (but it's quite easy because the author has already provided the scripts to do that beside the code) The script that follow can be launched in a directory outside you project (in order to not pollute everything) and then you can copy & paste only the built libraries inside your project where do you prefer
Hope this works, i'm not at work now and i'm not able to check if this was the routine that i really did |
Thanks @Aduer! I'll be trying those instructions out, and let you know if i find anything different! |
New release of sticky states 1.4.1 should address many problems from this thread. For webpack + (ES6 or Typescript) users:
For webpack + ES6 users:
For UMD bundle
|
Thanks @christopherthielen ! will give it a shot soon. |
@christopherthielen when I try to follow your instructions above I get a build error like - "invalid expression export' or similar. |
@christopherthielen Can you provide any example If my project is using bower and old vanilla js without any js module loaders, then how to use sticky-state? |
@mohanrao I have exactly the same structure. Did you find a solution yet? |
Right now I did what @Aduer suggested. No other options |
import {StickyStatesPlugin} from '@uirouter/sticky-states'; Codes above will reach webpack compile errors: WARNING in ./~/@uirouter/sticky-states/lib/stickyStates.d.ts
Module parse failed: /Users/Cynn/project/node_modules/@uirouter/sticky-states/lib/stickyStates.d.ts Unexpected token (2:8)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:8)
at Parser.pp$4.raise (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp.semicolon (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:581:61)
at Parser.pp$1.parseExpressionStatement (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:966:10)
at Parser.pp$1.parseStatement (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:730:24)
at Parser.pp$1.parseTopLevel (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/Cynn/project/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/Cynn/project/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock.<anonymous> (/Users/Cynn/project/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/Users/Cynn/project/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/Cynn/project/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /Users/Cynn/project/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/Users/Cynn/project/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /Users/Cynn/project/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)
@ ./~/@uirouter/sticky-states/lib ^\.\/.*$ I use webpack + ts-loader + babel to compile (code transform), here goes my webpack loader configuration: module.exports = {
module: {
loaders: [
{
test: /\.tsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'ng-annotate!babel?' + JSON.stringify({
presets: ['es2015', 'stage-3'],
plugins: ['transform-runtime', 'transform-decorators-legacy', 'transform-class-properties']
}) + '!ts-loader?allowJsEntry=true' // plugins here is not necessary for everyone
}
]
}
}; I excluded Thanks @christopherthielen . 🍨 Solution: import uiRouter from 'angular-ui-router';
import {StickyStatesPlugin} from '@uirouter/sticky-states/_bundles/ui-router-sticky-states';
export default angular
.module('router', [
uiRouter
])
.config(['$uiRouterProvider', function ($uiRouterProvider) {
$uiRouterProvider.plugin(StickyStatesPlugin);
}])
.config(['$stateProvider', function ($stateProvider) {
// states ...
$stateProvider.state('app', {});
}])
.name; devDependencies: ├── [email protected]
├─┬ @uirouter/[email protected]
├─┬ [email protected]
│ └── @uirouter/[email protected] |
In case anyone comes here that uses no bundler at all (like me), here is my approach:
<script src="/deps/angular-ui-router/release/ui-router-core.js"></script>
<script src="/deps/angular-ui-router/release/ui-router-sticky-states.js"></script>
<script src="/deps/angular-ui-router/release/ui-router-angularjs.js"></script>
angular.module('app.state', ['ui.router']).config([
'$uiRouterProvider',
function($uiRouterProvider) {
var StickyStates = window['@uirouter/sticky-states'];
$uiRouterProvider.plugin(StickyStates.StickyStatesPlugin);
}
]); |
This should definitely be put on the front README |
What if copying files is not a possibility? Is it possible to create ng1-sticky-states github project that would be prebuild for ng1? Unfortunately, I need it to work with simple bower install. |
I added 5 example sticky-states projects:
|
Sticky states will not be published on bower. Bower is deprecated. You'll have to find some way to copy files from node_modules. |
@christopherthielen Thank u very much for AngularJS + npm + script tags example . it worked for me |
This #4 (comment) worked for me. |
@molehillrocker, I tried your solution. It somehow did not work for me. I then printed out the variable Where am I making a mistake? Here is the stub from my index.html: ` <script src="scripts/plugins/angular-ui-router/release/ui-router-core.min.js" ></script>
`
Please help. |
Also, do you have to add all states using stateRegistry of $uiRouteProvider like @christopherthielen has done in his angularjs + npm + scripts example: `var stateRegistry = $uiRouterProvider.stateRegistry; stateRegistry.register({ Can I not add states the following way?: `$stateProvider
|
Hello,
can you please provide more information about how to install the sticky-states for Angular 1. I'm using bower instead of NPM. How about the ui-router-core on bower?
How should I import the required files? Usually I'm using the <script> tag to import files.
The Import-Function doesn't work on the Client-Side (or require).
import {StickyStatesPlugin} from "ui-router-sticky-states";
angular.module('myapp', ['ui.router']).config(function($uiRouterProvider) {
$uiRouterProvider.plugin(StickyStatesPlugin);
});
Best Regards
The text was updated successfully, but these errors were encountered: