0

I am a learner, and sorry if it is not the right place to ask a trivial question, please direct me to the suitable forum.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title> Angular Example: 2</title>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js"></script>
    <script type="text/javascript" 
src="FirstCtrl.js"> </script>

</head>

<body>


<!-- Controllers-->

<div ng-app="">
    <div ng-controller="FirstCtrl">
        <h1>{{data.message + " world"}}</h1>
        <div class="{{data.message}}">
            Wrap me in a foundation component
        </div>
    </div>
</div>

</body>
</html>

FirstCtrl.js

function FirstCtrl($scope){

    $scope.data = {message: "Hello"};
}

If I use the following version it works.

src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>

How can I decide which one to use? What is the issue here

2
  • 3
    Global controllers were disabled in 1.3.0-beta.15. Read the breaking change here: github.com/angular/angular.js/blob/master/… Commented Nov 30, 2014 at 11:49
  • Use ng-class="data.message" instead of class="{{data.message}}" Commented Nov 30, 2014 at 12:46

1 Answer 1

3

In the comments tasseKATT specified exactly what is going on correctly.

In order to resolve this using angular 1.3+ you must define your module, both in markup and in code:

<div ng-app="myApp">
angular.module('myApp', []);

Then add your controller to that module:

              //name of the controller \/
angular.module('myApp').controller('FirstCtrl', FirstCtrl);
           //function that defines your controller /\
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. Can you please suggest me best resource or book to learn (probably the latest version) of AngularJS? I face lot of difficulty even to execute the ready-made code given with tutorials available online. Thanks and appreciate your help.
Honestly there aren't many external breaking changes from 1.2.x to 1.3.x except for this one that you have already crossed. There a lot of performance improvements and some extras added, so I would stick to what you've found so far re: 1.2.x for reference.

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.