[英]How to properly use ng-click in angularjs?
Hi I have been learning angularjs over a week now. 嗨,我已经学习了一周以上的angularjs。 I have a question on ng-model.
我对ng-model有疑问。
my question is I have a field called firstname:. 我的问题是我有一个名为firstname:的字段。 When I give the name and hit the submit button.
当我输入名称并点击提交按钮时。 The firstname has to be displayed in another field called Name:
名字必须显示在另一个名为Name的字段中:
Here is the code I wrote: 这是我写的代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js">
</script>
<script type="text/javascript">
var emp= angular.module("empdet",[])
emp.controller("empctrl",function($scope){
$scope.form= function(){
var display= $scope.firstname;
}
});
</script>
</head>
<body ng-app="empdet">
<div ng-controller="empctrl">
<div>First Name: <input type="text" ng-model="firstname"></div>
<button type="button" ng-click=form()>SUBMIT</button>
<div>Name:{{display}}</div>
</div>
</body>
</html>
Any help is appreciated. 任何帮助表示赞赏。
Thanks 谢谢
只需将其更改为:
$scope.display = $scope.firstname;
Your var display
is internal. 您的
var display
是内部的。 Change it to $scope.display
. 将其更改为
$scope.display
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.