{{}}运算符不在angularjs中工作

Rah*_*hul -4 javascript angularjs

当我尝试打印变量名时,它打印{{name}}而不是变量,我不知道我哪里出错了.

HTML:

<!DOCTYPE html>
<html ng-app="MyTestApp">
<head>
    <title>Angular test</title>
    <script type="text/javascript"> src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script type="text/javascript"> src = "app.js"></script>
</head>
<body>
    <div id="divx" ng-controller="MyTestController">
        <input type="text" ng-model="name">
                <h2>{{name}}</h2>
    </div>  

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

(function () {
'use strict';

angular.module('MyTestApp', [])

.controller('MyTestController', function ($scope) {
  $scope.name = "Angular";
  $scope.sayHello = function () {
    return "From function";
  };
});

})();
Run Code Online (Sandbox Code Playgroud)

Saj*_*ran 5

有两个问题,

(i)脚本应该被称为

  <script type="text/javascript" src="angular.min.js"> </script>
  <script type="text/javascript" src="app.js"> </script>
Run Code Online (Sandbox Code Playgroud)

(ii)您不应放在{{name}}输入元素内.在一个<h1><p>标签内更改如下.

DEMO

(function () {
'use strict';

angular.module('MyTestApp', [])

.controller('MyTestController', function ($scope) {
  $scope.name = "Angular";
  $scope.sayHello = function () {
    return "From function";
  };
});

})();
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html ng-app="MyTestApp">
<head>
    <title>Angular test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body>
    <div id="divx" ng-controller="MyTestController">
        <input type="text" ng-model="name">
        <h1> {{name}}</h1>
    </div>  

</body>
</html>
Run Code Online (Sandbox Code Playgroud)