3

I'm trying to set up a demo angular app but for some reason my partial (partials/test.html) content isn't loading into the layout file. Here's the index.html:

<!DOCTYPE html>
<html lang="en" ng-app="btq">
   <head>
      <meta charset="utf-8" />
      <title>NgView Test</title>
   </head>
   <body>
      <p>Some stuff on the page.</p>
      <div ng-view></div>
      <script src="js/angular.js"></script>
      <script src="js/app.js"></script>
   </body>
</html>

AngularJS is version 1.0.7. app.js contains the following:

'use strict';

// Declare app level module which depends on filters, and services
angular.module('btq', []).
  config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/dashbaord', {templateUrl: 'partials/test.html', controller: 'DashboardCtrl'});
    $routeProvider.otherwise({redirectTo: '/dashboard'});
  }]);

/* Controllers */

angular.module('btq.controllers', []).
  controller('DashboardCtrl', [function() {

  }]);

I'm obviously missing something simple. Any help would be appreciated!

2 Answers 2

2

May be its because of "typo". You wrote "dashbaord" instead of "dashboard" here:

$routeProvider.when('/dashbaord' , ...
Sign up to request clarification or add additional context in comments.

1 Comment

There was definitely a typo, can't believe I didn't catch that. Thanks!
1

Change

angular.module('btq.controllers', [])

to

angular.module('btq')

otherwise this creates a second app in your app.js

3 Comments

Doing so causes the partial content to not load. Leaving it as btw.controllers loads the partial content but also throws a Error: Argument 'DashboardCtrl' is not a function, got undefined
Ah I see whats wrong, I needed to pass btq.controllers to the btq module like so: angular.module('btq', ['btq.controllers'])
That will work. That way you create two modules and inject the second module as a dependency in the first. Another option is to use one module for both. See my update, there was a typo in my answer. The second [] should not have been there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.