Saiful
Saiful

Reputation: 414

AngularJS version issue?

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

Upvotes: 0

Views: 115

Answers (1)

Brocco
Brocco

Reputation: 65053

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 /\

Upvotes: 3

Related Questions