简体   繁体   中英

cannot load the message properly on angular

<!DOCTYPE html>
<html ng-app>
  <head>
    <script data-require="angular.js@*" data-semver="1.4.3"                src="https://code.angularjs.org/1.4.3/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="MainController">
    <h1>This is the message {{message}}</h1>
  </body>
</html>

and my script file has

var MainController = function($scope) {
  $scope.message = "Hi this is great ";
};

but still the result is showing {{message}} and not the actual message

Here is a working example:

<body ng-app="myApp">
    <div ng-controller="MainController">
      Hello, {{message}}!
    </div>
</body>


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


var MainController = function($scope) {
    $scope.message = "Hi this is great ";
}

http://jsfiddle.net/sinaidoron/1c12r4hr/1/

HTML Code :

<!DOCTYPE html>
<html ng-app="demo">
    <head>
        <meta charset="utf-8" />
        <title>AngularJS Plunker</title>
        <script>
            document.write('<base href="' + document.location + '" />');
        </script>
        <link rel="stylesheet" href="style.css" />
        <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.3/angular.js" data-semver="1.4.3"></script>
        <script src="app.js"></script>
    </head>
    <body ng-controller="MainController">
        <p>This is the message {{message}}</p>
    </body>
</html>

And script.js

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

app.controller('MainController', function ($scope) {
    $scope.message = "Hi this is great ";
});

Working example Plunker Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM