Tomek Buszewski
Tomek Buszewski

Reputation: 7935

Angular fails to load module

I'm learning AngularJS and I have a strange problem with it. My code is as follows:

html:

<!doctype html>
<html ng-app="blogApp">
<head>
    <title>Test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
    <script src="script.js"></script>
</head>
<body>
<div class="container" ng-controller="blogPostsCtrl">
    <article ng-repeat="post in posts">
        {{post.title}}
    </article>
</div>
</body>
</html>

js:

var blogApp = angular.module('blogApp', ['ngSanitize', 'ngRoute']);

blogApp.controller('blogPostsCtrl', function($scope, $http) {
    $http.get('//jsonplaceholder.typicode.com/posts').success(function(data) {
        $scope.posts = data;
        $scope.postsLoaded = 'visible-lg';
    });
});

It should be working, as I create a module and then controller for it. But it returns an error: https://goo.gl/UWFMNm. What can I do?

Upvotes: 0

Views: 93

Answers (1)

casraf
casraf

Reputation: 21694

Looks like you didn't install ngRoute. It comes separately in its own file/module.

As the error page says:

Using ngRoute

In AngularJS 1.2.0 and later, ngRoute has been moved to its own module. If you are getting this error after upgrading to 1.2.x or later, be sure that you've installed ngRoute.

ngRoute Documentation - include the file from there for it to work

Upvotes: 1

Related Questions