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)
有两个问题,
(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)
| 归档时间: |
|
| 查看次数: |
418 次 |
| 最近记录: |