Heim > Fragen und Antworten > Hauptteil
Entschuldigung, warum wird in meinem HTML-Code {{greeting.text}}, Angular anstelle von Hello, Angular
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>
<p ng-controller="HelloAngular">
<p>{{greeting.text}},Angular</p>
</p>
</body>
</html>
JS
function HelloAngular($scope) {
$scope.greeting ={
text:'hello'
};
}
Die Seite wird angezeigt als: {{greeting.text}},Angular
三叔2017-07-04 13:46:55
例子
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/...
<body>
<p ng-app="myApp" ng-controller="myCtrl">
名: <input type="text" ng-model="firstName">
姓: <input type="text" ng-model="lastName">
姓名: {{firstName + " " + lastName}}
</p>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
</script>
</body>
</html>