gpt4 book ai didi

html - Angularjs 不绑定(bind)数据和 html 不打印范围变量

转载 作者:太空宇宙 更新时间:2023-11-04 15:56:49 25 4
gpt4 key购买 nike

这是我的完整代码,angular 没有在 html pice 的 body 标签中打印 vars,console.log() 到处都在工作。 ng-click 提交按钮也有效。

<html ng-app="fb">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap /3.3.7/css/bootstrap.min.css"
integrity="sha384- BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5 /angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-cookie/4.1.0/angular-cookie.js"></script>

<script>
var app=angular.module('fb', []);

app.controller('home',function($scope){
var hi;
$scope.hi=5;
//$rootScope.hola=9;
console.log($scope.hi);
//console.log($rootScope.hola);

$scope.submitSignup=function()
{
var hi;
$scope.hi=5;
//$rootScope.hola=9;
console.log($scope.hi);
//console.log($rootScope.hola);
console.log($scope.username);
alert('button pressed');
};
});

</script>
<head>
<title>Index</title
</head>

<body>
<div ng-controller='home'>
<input type="text" placeholder="Username" ng-model="username">
<br>
<input type="password" placeholder="Password" ng-model="password">
<br>

<button type="button" ng-click="submitSignup()">SignUp</button>

<br>

<p> {{username}} </p>


<p> {{hi}} </p>


{{hola}}


</div>

<p> index </p>
</body>
</html>

为此绞尽脑汁好几个小时,我们将不胜感激。

最佳答案

使用 ng-app="fb" 在您的模板中添加 ng-app>

演示

 
<html ng-app="fb">
<head>
<title>Index</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script>
<script>
var app=angular.module('fb', []);
app.controller('home',function($scope){
var hi;
$scope.hi=5;
//$rootScope.hola=9;
console.log($scope.hi);
//console.log($rootScope.hola);

$scope.submitSignup=function()
{
var hi;
$scope.hi=5;
//$rootScope.hola=9;
console.log($scope.hi);
//console.log($rootScope.hola);
console.log($scope.username);
alert('button pressed');
};
});
</script>
<body>
<div ng-controller='home'>
<input type="text" placeholder="Username" ng-model="username">
<br>
<input type="password" placeholder="Password" ng-model="password">
<br>
<button type="button" ng-click="submitSignup()">SignUp</button>
<br>
<p> {{username}} </p>
<p> {{hi}} </p>
{{hola}}
</div>
<p> index </p>
</body>
</html>

关于html - Angularjs 不绑定(bind)数据和 html 不打印范围变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44997437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com