您的位置:首页技术文章
文章详情页

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

【字号: 日期:2024-03-03 15:51:07浏览:16作者:猪猪

问题描述

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

<!DOCTYPE html><html ng-app><head> <meta charset='UTF-8'> <title>Title</title> <script src='https://www.haobala.com/wenda/js/angular.js'></script> <script src='https://www.haobala.com/wenda/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’ };}

页面显示为:{{greeting.text}},Angular

问题解答

回答1:

自己看看官网链接描述就晓得了,你这函数也没调用啊

回答2:

数据双向绑定,在angular上教程上

回答3:

例子<!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>

回答4:

在你的html文档中 ng-app 应该赋值(和js中定义的相同),eg: ng-app='DemoApp'

标签: HTML