HAraTest
HAraTest

Reputation: 5

How to properly use ng-click in angularjs?

Hi I have been learning angularjs over a week now. I have a question on ng-model.

my question is I have a field called firstname:. When I give the name and hit the submit button. The firstname has to be displayed in another field called 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

Upvotes: 0

Views: 32

Answers (2)

MPawlak
MPawlak

Reputation: 715

Your var display is internal. Change it to $scope.display.

Upvotes: 1

developer033
developer033

Reputation: 24874

Just change it to:

$scope.display = $scope.firstname;

Upvotes: 2

Related Questions