请问为什么我的html显示的是{{greeting.text}},Angular而不是Hello,Angular

我是在webstorm工具上写的代码

html:

<!DOCTYPE html>
<html ng-app>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/angular.js"></script>
    <script src="js/HelloAngular-MVC.js"></script>
</head>
<body>
    <div ng-controller="HelloAngular">
        <p>{{greeting.text}},Angular</p>
    </div>
</body>
</html>

js:

function HelloAngular($scope) {
    $scope.greeting ={
        text:'hello'
    };
}

结果:http://img.mukewang.com/595607cb0001c05f02290057.jpg

呆呆呆
浏览 2305回答 1
1回答

李晓健

这你这种写法应该是很老的angular的版本写法,新的版本已经不支持这种写法了。<!DOCTYPE html> <html ng-app="myApp"> <head>     <meta charset="UTF-8">     <title>Title</title>     <script src="js/angular.js"></script>     <script src="js/HelloAngular-MVC.js"></script> </head> <body>     <div ng-controller="HelloAngular">         <p>{{greeting.text}},Angular</p>     </div> </body> </html>var app = angular.module('myApp', []); app.controller('HelloAngular', function($scope) {     $scope.greeting ={         text:'hello'     }; });你可试一下这样写。如果你的问题已解决,请记得采纳答案!
打开App,查看更多内容
随时随地看视频慕课网APP