0
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>

</head>
<body>
<h2>Form Validation Example</h2>
<form name="myForm" novalidate="novalidate" data-ng-app="myapp" data-ng-controller="myc">

<p>User Name:<br>
<input type="text" name="fname" ng-model="fname" data-ng-minlength="10" data-ng-required="true" placeholder="Enter name" class="myname">

</p>

<p>Email:<br>
<input type="text" name="mail" ng-click="click($event)" data-ng-model="mail" data-ng-required="true" class="mymail" placeholder="enter mail id"/>

</p>

 <input type="submit" value="click" ng-click="click()" />

  </form>

<script src="angularjs/angular.js"></script>

<script>
var app =angular.module("myapp",[]);

app.controller('myc',function($scope)
        {   
            var fname=$scope.fname;
            $scope.click = function()
            {
                console.log("name "+fname);
                alert("name "+fname);
            }

        });
</script>

</body>
</html>

I want to get a value which is entered by the user and after that I want to display it in the browser.

I don't want to set the value using $scope inside the controller. I tried many times but I was unsuccessful to do it. Can anybody help me?

1 Answer 1

2

Just pass the ng-model in click handler function as a parameter.

<input type="text" name="mail" data-ng-model="mail" data-ng-required="true" class="mymail" placeholder="enter mail id"/>

<input type="submit" value="click" ng-click="click(mail)" />

Show the model value in alert as

 $scope.click = function(mail)
    {
        console.log("mail "+mail);
        alert("mail "+mail);
    }
Sign up to request clarification or add additional context in comments.

3 Comments

when i clicked on input text filed it displayed undefined.
@vickykumarjaiswal type something and then click.
i wanted to do so but but when ever i enter into textField it generate event and display undefine.event should be triggered when i click on click button.

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.