0

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

2 Answers 2

2

Just change it to:

$scope.display = $scope.firstname;
Sign up to request clarification or add additional context in comments.

1 Comment

@HAraTest glad that it helped.. can you accept the answer?
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.