2

value of $scope.user.name should be changed to 'please enter name' , i should get 'please enter name' when click on reset button.

$scope.user = {};
$scope.reset =function(dta){
       $scope.dta = 'please enter name';
     }

       <input type ="text" ng-model="user.name">

       <button ng-click="reset('user.name')">Reset</button>
2

4 Answers 4

2

Just remove '' from user.name

Convert this

<button ng-click="reset('user.name')">Reset</button>

to this

<button ng-click="reset(user.name)">Reset</button>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to pass object and property separately, not as a single string.

And it is much better to use attribute placeholder instead of applying it to the object.

https://jsfiddle.net/wtq0mmgj/1/

UPDATE:

passing user.name without '' won't work because you apply value to $scope.dta instead of target object, so you'll be able to see the value in {{dta}}, but not in {{user.name}}

Comments

0

Try this:

$scope.reset =function(){
  $scope.user.name= 'please enter name';
}

<input type ="text" ng-model="user.name">

<button ng-click="reset()">Reset</button>

Comments

0

When you pass parameter dont use ''

<input type ="text" ng-click="reset(user.name)">

DEMO

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.dta ="test";
$scope.reset =function(dta){
       $scope.dta = 'please enter name';
     }
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
     
    <input type ="text" ng-model="dta">
     <button ng-click="reset(user.name)">reset</button>
</div>
</body>
</html>

1 Comment

i have used reset button onclick of that text input must reset

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.