0
  • I have a problem to show INPUT field when do some action.

    • I have BUTTON (Click here) as soon as user made a click event on button i wanted to show input field
    • I have done this by using jQuery.

    Can any one help me in Angular.js

3
  • you can try the angular directive as mentioned in this post stackoverflow.com/questions/24423152/… Commented Apr 17, 2015 at 6:57
  • Try too ad ng-show="someVariable" to your TextBox and set an ng-click="OnLinkClicked()" on your link and set someVariable = true in your OnLinkClicked Commented Apr 17, 2015 at 6:57
  • please feedback bu selecting right answer Commented Apr 9, 2017 at 1:33

3 Answers 3

4
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.boxShow = false;
});
</script>
<div ng-app="myApp">
    <div ng-controller="myCtrl">
        <a href="#" ng-click="boxShow=!boxShow">show box</a>

        <div ng-show="boxShow">
            <textarea rows="4" cols="50">text</textarea>
        </div>
    </div>
</div>

https://jsfiddle.net/bxwjpmaa/1/

Sign up to request clarification or add additional context in comments.

Comments

1

HTML

 <div class="btn btn-primary" ng-click="openTextBox();">Click Me To open text box</div>
 <div ng-show="openTextBox == true">
   <input type="text"/>
 </div>

SCRIPT :

 $scope.openTextBox = function () {
     $scope.openTextBox = true;
 }

please don't take scope variables and function names same example here

 $scope.openTextBox = function () {
   $scope.openTextBox = true;
   }

//this is not correct as per angular documentation because scope.openTextBox name already assigned to scope function,again its assigning scope variable "$scope.openTextBox = true" here u will get errors when ever u clicked div second time" TypeError: boolean is not a function" it will throw this error.so please dont use which is already assigned scope function dont assign scope variable

see this fiddle url : https://jsfiddle.net/veerendrakumarfiddle/bxwjpmaa/2/

Comments

0

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<ol>
<li ng-repeat="element in elements">
    <input type="text" ng-model="element.value"/>
    </li>
</ol>
<br/>
<b>Click here to add Textbox:</b><br/><input type="button" value="New Item" ng-click="newItem()"/>
<br/>
<br/>

<b>Click here to see ng-model value:</b><br/>
<input type="button" value="submit" ng-click="show(elements)">

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 var counter=0;
    $scope.elements = [ {id:counter, value : ''} ];

    $scope.newItem = function(){
        counter++;
        $scope.elements.push(  { id:counter,value:''} );
        
    }
    
    $scope.show=function(elements)
    {
        alert(JSON.stringify(elements));
        
    }
  
});
</script>
</body>
</html>

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.