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

Angular is not defined when using requirejs #67

Open
YonatanKra opened this issue Mar 19, 2015 · 11 comments
Open

Angular is not defined when using requirejs #67

YonatanKra opened this issue Mar 19, 2015 · 11 comments
Labels

Comments

@YonatanKra
Copy link

I've read two issues here, but the solutions don't work for me.
When I run the karma start regularily it says:
angular is not defined
Then, when I add:
public/lib/angular/angular.js
To the files property I get:
Warning tried to load angular twice
And I also get:
Unexpected request: GET TEMPLATEFILEPATH
Any idea how to solve this?

@sparmboy
Copy link

You need to define it in your require path and include a shim:

    paths: {
        'angular':'lib/angular/angular',
        'partials':'partials/myPartial.html',
    },

    shim: {
        'angular': {
            exports: 'angular'
        },
        'partials': {
            exports: 'partials',
            deps: ['angular']
        }
    },

@YonatanKra
Copy link
Author

Thanks.
But this doesn't work as well. Same error (angular is not defined).
It doesn't even shout about something I test about - just some random template file.
For instance, i test the directive "layersMenu", which has the template file "partials/layersMenu.html" but the error is thrown for: "partuals/mainContent.html".
I've lost a lot of hair over this one.
Any other solutions?

@YonatanKra
Copy link
Author

I somehow managed to fix "something". A lot of trial and error...
I have no idea what the issue is now, but I'm getting a whole new world of errors - requirejs can't find the files and the "no time stamp" for a lot of files, so this case can be closed I guess...

@sparmboy
Copy link

Yeah I went through the no timestamp issue this morning too! Heres my solution:

var tests = [];
/**
 *
 * The magic runes for removing the "no timestamp issue"
 *
 * https://github.com/karma-runner/karma-requirejs/issues/6
 *
 * You need these two for loops
 *
 */
for (var file in window.__karma__.files) {
    window.__karma__.files[file.replace(/^\//, '')] = window.__karma__.files[file];
}

for (var file in window.__karma__.files) {
    if (window.__karma__.files.hasOwnProperty(file)) {
        if (file.match('.*specs.*spec.js') ) {
            tests.push(file.replace(/^\//, ''));
        }
    }
}

put this at the top of your test-main.js (or whatever) require config

@YonatanKra
Copy link
Author

Thanks :)
I already put these.
The issue is with two things:

  1. With my template files.
  2. With a 3rd party component (cesium.js), when I'm using it's AMD version for development
    The rest loads fine and I can run tests when using the minified cesium version and/or when dealing with none templateUrl directives. I'd might just give up on the templateUrl thing...

@YonatanKra
Copy link
Author

The solution was more "elegant"... I've created a new cesium_test.js for the tests with the ammended paths in the define statement... and it now works
Yohoo - got some testing to do now.
Thanks a lot :)

@YonatanKra
Copy link
Author

@sparmboy - regarding the "shim" solution. Do I need to define this for all of my template files? I have a LOOOOT of those...

@YonatanKra YonatanKra reopened this Apr 22, 2015
@sparmboy
Copy link

@yccteam Unfortunatey yes, that is the only way Ive managed to get it working.

It'd be great if the ngHtml2JsPreprocessor moduleName option did the packaging of all template files into a single file with different module names but it doesnt appear to work that way (unless I'm doing something wrong)

@alouiseq
Copy link

@yccteam - I'm going through the same issue with 'angular not defined'. Can I see how you went about to resolve this? I have a module name defined in the ngHtml2JsPreprocessor and placed the module in the path and shim of test-main.js, but it still doesn't work.

@YonatanKra
Copy link
Author

YonatanKra commented Sep 28, 2015 via email

@YonatanKra
Copy link
Author

What I did eventually was to use requirejs!text plugin in order to load my template files, and then I put them in $templateCache.
It's a pain at first, but now I see many benefits... I can edit my templates on the fly and compile them, for instance.

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

No branches or pull requests

4 participants