Gagandeep Singh
Gagandeep Singh

Reputation: 11

AngularJs and ng-controller

I have just started learning AngularJS but I am stuck at this point. I made three files in one project:

1.Index.html
2.Angular.min.js( downloaded from official site)
3.Script.js

But when I am opening html in browser I am not getting the value of test property. It just shows the {{test}} (not the value). Will be very thankful if you help me out.

 <!DOCTYPE html>
    <html lang="en" ng-app = "myapp">
    <head>
       <meta charset="UTF-8">
       <title>Document</title>
    </head>
    <body  ng-controller = "MyCtrl">
           {{test}}
           <script src = "angular.min.js"</script>
           <script src = "script.js"></script>
    </body>
    </html>***

Script.js file is

var app = angular.module('myapp',[]);

app.controller('MyCtrl', ['$scope', function($scope){
    $scope.test = "Welcome to my world";

}]);

Upvotes: 1

Views: 41

Answers (1)

shaunhusain
shaunhusain

Reputation: 19748

Check the network tab be sure angular itself is actually loading copying and pasting your code into a running sample.

var app = angular.module('myapp',[]);

app.controller('MyCtrl', ['$scope', function($scope){
    $scope.test = "Welcome to my world";

}]);
<!DOCTYPE html>
    <html lang="en" ng-app = "myapp">
    <head>
       <meta charset="UTF-8">
       <title>Document</title>
    </head>
    <body  ng-controller = "MyCtrl">
           {{test}}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
           <!--
           you were missing a > here
           <script src = "angular.min.js"</script>
           <script src = "script.js"></script>
-->
    </body>
    </html>

Upvotes: 2

Related Questions