我正在尝试使用角度创建简单的网页。 我有2个文本框和2个按钮。 1按钮设置文本框中的prdefine值 2编写一些文本并添加。 当我点击添加按钮时,文本框1和2应该在另一个地方打印屏幕。我如何获得angularjs中的文本框值?
这里的代码。 的index.html
<!DOCTYPE html>
<html lang="en" ng-app="chatApp">
<head>
<meta charset="UTF-8">
<title>Chat Application</title>
<script src="scripts/angular.min.js"></script>
<script src="scripts/app.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<script>
function myFunction() {
document.getElementById("Text1").value = "Johnny Bravo";
}
</script>
<body ng-controller="chatController">
<div class="container">
<div class="chatArena">
<div class="userList">
<ul>
<li ng-repeat="person in listPeopleAdded" >{{person.name}}</li>
<li ng-repeat="person in pretext" >{{person.name}}</li>
</ul>
</div>
</div>
<div class="chatAdder">
<input type='text' ng-model='textbox' name='textbox1' id='Text1'>
<button onclick="myFunction()" ng-click="pset(textbox)">set value</button>
<br>
<br>
<input type="text" name="personName" class="chatInputPersonName" ng-model="personName">
<button ng-click="addPerson()">Add Value</button>
</div>
</div>
</body>
</html>
在app.js警报($ scope.textbox)app.js
var app = angular.module('chatApp',[]);
app.controller('chatController',function($scope){
$scope.pretext=[];
$scope.listPeopleAdded = [];
$scope.addPerson = function(){
$scope.listPeopleAdded.push({name:$scope.personName})
}
$scope.pset = function(textbox){
alert($scope.textbox)
$scope.pretext.push({name:$scope.textbox})
}
});
显示未定义的值。
只使用'ngClick'。你也不需要把它作为参数传递。 – developer033