4

I started learning AngularJS so I created two html pages:

index.html

<!DOCTYPE html>
<html ng-app="TodoApp" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script src="Scripts/jquery-1.10.2.js"></script>
        <script src="Scripts/bootstrap.js"></script>
        <script src="Scripts/angular.js"></script>
        <script src="Scripts/angular-resource.js"></script>
        <link href="Content/bootstrap.css" rel="stylesheet" />
        <script src="Scripts/app.js"></script>
        <title>Angular Tutorial</title>
    </head>

    <body>
        <div class="container">
               <div ng-view></div>
        </div>
    </body>

</html>

and list.html

<input type="text" ng-model="test">
<h1>Hello: {{test}}</h1>

The app.js looks like this

var TodoApp = angular.module("TodoApp", ["ngResource"]).
    config(function ($routeProvider) {
        $routeProvider.
            when('/', { controller: ListCtrl, templateUrl: "list.html" }).
            otherwise({ redirectTo: '/' });
    });


var ListCtrl = function ($scope, $location)
{
    $scope.test = "testing";        
};

Unfortunately, when I open the index.html page it is blank. What can be the cause of the problem?

5

4 Answers 4

5

As you mentioned the error:-

1) Add angular-route.js file in main page.

2) Add 'ngRoute' dependency in angular main app.

Doc:-https://docs.angularjs.org/tutorial/step_07

Sign up to request clarification or add additional context in comments.

Comments

1

also you need to mention the controller in your HTML with ng-controller="ListCtrl" to initialize it.

And do not declare your controller that way, you must do

todoApp.controller('ListCtrl', ['$scope', 'dep1', 'dep2', function($scope, dep1, dep2) {

  $scope.test = "testing";

}]);

1 Comment

I've been watching the tutorial from 2013., I suppose there are some version differences then :/ Thank you for the feedback!
0

It seems that you are missing the controller's definition:

TodoApp.controller('ListCtrl', ListCtrl);

This should fix your issue

1 Comment

The controller is defined in the module config, but thank you very much for the response anyway, I found the solution :)
0

You can also take a look at yeoman. It will help you to start with angularjs in zero time.

http://yeoman.io/codelab.html

Comments

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.