sanitize via requirejs

591 views
Skip to first unread message

m.wo...@gmx.de

unread,
Dec 25, 2013, 8:26:53 AM12/25/13
to ang...@googlegroups.com
Hi there,

I'm currently in need of ngSanitize for an Angular project. But I dont get it to work.
I'm using the requirejs-angular-seed from https://github.com/angular/angular-seed

The thing is, I have to use 'ng-bind-html' and therefore I need to import the angular-sanitize module.
But with requireJS it never seems to get loaded.... this is my require-configuration-file:

require.config({
    paths: {
        angular: '../bower_components/angular/angular',
        angularSanitize: '../bower_components/angular-sanitize/angular-sanitize'
    },
    shim: {
        'angular' : {'exports' : 'angular'},
        'angularSanitize' : {'deps' : 'angular'}
    },
    priority: [
        "angular"
    ]
});

//http://code.angularjs.org/1.2.1/docs/guide/bootstrap#overview_deferred-bootstrap
window.name = "NG_DEFER_BOOTSTRAP!";

require( [
    'angular',
    'app'
], function(angular, app) {
    'use strict';

    var $html = angular.element(document.getElementsByTagName('html')[0]);

    angular.element().ready(function() {
        angular.resumeBootstrap([app['name']]);
    });
});



I dont know how to make angular-sanitize work with requireJS? Any recommendations or best practices?


Thanks in advance and cheers,
Martin
Message has been deleted

Edward

unread,
Dec 26, 2013, 1:49:39 AM12/26/13
to ang...@googlegroups.com
RequireJS takes charge of loading js files into browser, while Angular injects correct
objects when creating modules.
That is to say, your js files should be loaded into the browser before Angular injection.

so you need to

    require([
        'angular',
        'app',
        'angularSanitize'
    ......

BTW, your requireJS main module seems a little strange, I just used the following logic,

    angular.bootstrap(document, [ "name" ]);

Hope this helps.

m.wo...@gmx.de

unread,
Dec 27, 2013, 1:11:00 PM12/27/13
to ang...@googlegroups.com
Hello Edward,

thanks for your reply - unfortunately, this doesn't work either. I always get an "invalid require call" error?!
The main module logic is from the seed-code. It's neccessary to do a deferred bootstrap but it doesnt seem to have any impact on the module-loading.
Do you have any other suggestions? Did you already make it work? I cant find any documentation on how to achieve this via requirejs - it seems to be only possible by inserting the sanitize-script manually in the page header.

Edward

unread,
Dec 27, 2013, 10:58:55 PM12/27/13
to ang...@googlegroups.com
Hello Martin,

I do make it work well in a large app which uses angular+requireJS.

the "invalid require call" occurs when there is a call like,
require('dependency', function (dependency) {});
so you need to change it 
require(['dependency'], function (dependency) {});
Could you pls check if there is such error in your other modules?

BTW, do you know this

m.wo...@gmx.de

unread,
Dec 28, 2013, 2:32:22 PM12/28/13
to ang...@googlegroups.com
Hello Edward,

yep, that was the error... I already got it by myself yesterday. Now it's working. Finally...  :)
Thanks for your help.
Reply all
Reply to author
Forward
0 new messages