locked
Doubt for AngularJS newbie RRS feed

  • Question

  • User1768510565 posted

    This is my first program in AngularJS, tried a lot but could not succeed.

    Here is my .html code:

    <!DOCTYPE html>
    <html ng-app>
    <head>
        <title>Introduction to AngularJS Application</title>
        <script src="Scripts/angular.js"></script>
        <script src="Scripts/MyScripts/Example01Scripts.js"></script>
    </head>
    <body ng-controller="MainController">
        <h1>{{message}}</h1>
    </body>
    </html>

    Here is my JavaScript code:

    var MainController = function ($scope) {
        $scope.message = "Hello, Angular!";
    };

    With the above code, I am just getting output as {{message}} as shown below, where expected is "Hello, Angular!":

    AngularJS Error

    Wednesday, April 15, 2015 12:18 AM

All replies

  • User1396448631 posted

    Are you using the latest angularjs script?

    Change your controller to the following

    <!DOCTYPE html>
    <html ng-app="myApp">
    <head>
        <title>Introduction to AngularJS Application</title>
        <script src="Scripts/angular.js"></script>
        <script src="Scripts/MyScripts/Example01Scripts.js"></script>
    </head>
    <body ng-controller="MainController">
        <h1>{{message}}</h1>
    </body>
    </html>
    
    
    
    var myApp = angular.module('myApp', []);
    
    myApp.controller('MainController', ['$scope', function ($scope) {
        $scope.message = "Hello, Angular!";
    }
    ]);

    Thursday, April 16, 2015 3:48 PM