0
  • 执行某些操作时显示INPUT字段时出现问题。

    • 一旦用户在我想显示输入字段的按钮上进行了单击事件,我就有了 BUTTON(单击此处)
    • 我通过使用 jQuery 做到了这一点。

    任何人都可以在 Angular.js 中帮助我吗

4

3 回答 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/

于 2015-04-17T07:15:04.617 回答
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/

于 2015-04-17T07:18:16.450 回答
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>

于 2017-06-28T17:18:22.477 回答