2

I'm trying to build an angularJs app, i'm also using requireJs with angularAMD package.

My project structure

 |root
 |-> bower_components
 |-> html
 |--> index.html
 |--> tmpl
 |---> test.html
 |-> js
 |--> app.js
 |--> main.js
 |--> controllers
 |---> account.js

My app.js file:

define(['angularAMD', 'angular-route'], function (angularAMD) {
    var app = angular.module("elara", ['ngRoute']);
    app.config(function ($routeProvider) {
        $routeProvider.when("/", angularAMD.route({
            templateUrl: '/html/tmpl/test.html', controller: 'registerController',
            controllerUrl: '/js/controllers/account.js'
        })).otherwise({redirectTo: "/"});
    });
    return angularAMD.bootstrap(app);
});

my main.js file

require.config({

    paths: {
        'angular': '/bower_components/angular/angular.min',
        'angular-route': '/bower_components/angular-route/angular-route.min',
        'angularAMD': '/bower_components/angularAMD/angularAMD.min'
    },
    shim: { 'angularAMD': ['angular'], 'angular-route': ['angular'] },
    deps: ['/js/app.js']
});

my index.html

<!DOCTYPE html>
<html>
    <head>
        <script data-main="/js/main.js" src="/bower_components/requirejs/require.js"></script>
    </head>
    <body>
    <div ng-view></div>
    </body>
</html>

my test html

<h1>test</h1>

So, i'm navigating to url /, on the network tab i can see that my controller and template is loaded, but content of the template is not rendered into ng-view element.

Sefa
  • 8,865
  • 10
  • 51
  • 82
  • It might be a conflict between angular and requireJS/angularAMD. You should use ```requireJS``` to load your controller instead of loading it with ```ng-route``` and ```controllerUrl```. --- P.S. If you can show what is it in your ```'/js/controllers/account.js'``` it will be easier to debug the problem. – Linh Pham Jan 04 '16 at 07:48

0 Answers0