Skip to content
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

ui-router problem with require js with AMD loading . #479

Closed
defyjoy opened this issue Oct 3, 2013 · 15 comments
Closed

ui-router problem with require js with AMD loading . #479

defyjoy opened this issue Oct 3, 2013 · 15 comments

Comments

@defyjoy
Copy link

defyjoy commented Oct 3, 2013

I tried this

http://stackoverflow.com/questions/19069769/router-not-found-error-in-ui-router-angularjs-with-requirejs/19161654?noredirect=1#19161654

unfortunately the answer didnt solve the problem . Its not able to load the angular ui router . it still shows the same error in both firefox and chrome . Any solution for this ?

@kuma0605
Copy link

I handle it. https://github.com/kuma0605/angular-require-uiRouter

main.js

require.config({

    paths: {
        'domReady': '../lib/requirejs-domready/domReady',
        'angular': '../lib/angular/angular',
        "uiRouter": "../lib/angular/angular-ui-router"
    },

    /**
     * for libs that either do not support AMD out of the box, or
     * require some fine tuning to dependency mgt'
     */
    shim: {
        'angular': {
            exports: 'angular'
        },
        'uiRouter':{
            deps: ['angular']
        }
    },

    deps: [
        // kick start application... see bootstrap.js
        './bootstrap'
    ]
});

app.js

define([
    'angular',
    'uiRouter',
    './controllers/index',
    './directives/index',
    './filters/index',
    './services/index'
], function (ng) {
    'use strict';

    return ng.module('app', [
        'app.services',
        'app.controllers',
        'app.filters',
        'app.directives',
        'ui.router'
    ]);
});

routes.js

define(['./app'], function(app) {
    'use strict';
    return app.config(function($stateProvider) {
        $stateProvider.state('view1',{
            url: '/view1',
            templateUrl: 'partials/partial1.html',
            controller:'MyCtrl1'
        })
        .state('view2',{
            url: '/view2',
            templateUrl: 'partials/partial2.html',
            controller: 'MyCtrl2'
        });
    })
});

it works! hahaha

@defyjoy
Copy link
Author

defyjoy commented Oct 15, 2013

Thanks man it works . This is the perfect solution 👍 👍

@defyjoy defyjoy closed this as completed Oct 15, 2013
@timkindberg
Copy link
Contributor

@kuma0605 I cleaned up your post a bit, great solution!!

@rsc092020
Copy link

I am creating a program that uses requirejs, angularjs, and want to use angular-ui-router, but I was having some problems and found this post. I tried the code from https://github.com/kuma0605/angular-require-uiRouter that was posted above, but I am getting an error

Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

when it is trying to load partial1.html or partial2.html

@eggers
Copy link

eggers commented Feb 6, 2014

Take a look at the detour project which has already done the integration.

@rsc092020
Copy link

Do you mean this project or are you talking about something else:

http://www.startersquad.com/examples/angularjs-requirejs-2/

@eggers
Copy link

eggers commented Feb 6, 2014

This is the one I was talking about: https://github.com/afterglowtech/angular-detour

@rsc092020
Copy link

Thanks man. I found what I was looking for.

@wishma2013
Copy link

If I want to compress and concat javascript file in requirejs+angular+ui-router project,How should I organize all my scripts file's?

@rhka
Copy link

rhka commented Aug 6, 2015

Hi, We are using stateprovider in our application. But, we want to load the controller files dynamically. I dont know how to acheive this. Could you please help me to do that. We are able to load the files dynamically using route provider. But, i want with Stateprovider. Thanks

@ghost
Copy link

ghost commented Sep 3, 2015

All, I observed that this code works as we use angular.bootstrap. Same does not work with ngApp. Any idea?

@CHEOLGUSO
Copy link

@kuma0605 thank you very much :D

@ejongg
Copy link

ejongg commented Apr 17, 2017

Did anyone managed to make this work on ui-router 1.0.0 ?

@linlak
Copy link

linlak commented Jan 8, 2018

Mine worked ui-router has a dependence for requires all you need to do in your app.js file you need to add angular-ui-router that is all you will be good to go. app.js should be like
define(['angular-ui-router','uirouter', etc],....);
uirouter is your file parth but angular-ui-router is a dependence for AMD that uirouter provides. I have to dig into uirouter and discovered that if you also go to the code in uirouter and you are good in require js you will it. It is at the beginning of the code. Tell me if it works for you. Thanks

@linlak
Copy link

linlak commented Jan 9, 2018

When using require js you don't have to use the ngApp directive to prevent auto bootstrap because if bootstrap happens before dependence files are loaded it produce errors that is why we have to use angular.bootstrap and not ngApp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants