使用AngularJS单击按钮

使用AngularJS单击按钮,angularjs,typescript,Angularjs,Typescript,我需要在我的表单中添加一个按钮,如果我单击该按钮,它将显示一个文本区域和一个提交按钮,因此在键入任何文本后,我将单击提交按钮,它将使用AngularJS在我的表单中打印复选框。 与上图相同。我不熟悉typescript,请帮助我解决此问题,使用ngClick指令: <button ng-click="yourFunction()">OK</button> OK 另外,在提出这样一个基本问题之前,请先阅读文档或教程/示例… <div data-ng-contr

我需要在我的表单中添加一个按钮,如果我单击该按钮,它将显示一个文本区域和一个提交按钮,因此在键入任何文本后,我将单击提交按钮,它将使用AngularJS在我的表单中打印复选框。


与上图相同。我不熟悉typescript,请帮助我解决此问题,使用ngClick指令:

<button ng-click="yourFunction()">OK</button>
OK

另外,在提出这样一个基本问题之前,请先阅读文档或教程/示例…


<div data-ng-controller="homeController">
    <div class="col-lg-1">
        <span class="glyphicon glyphicon-plus-sign" style="cursor:hand" aria-hidden="true" title="Add More" ng-click="onEnable()"></span>
    </div>
    <div class="col-lg-5">
        <input type="text" ng-if="isEnableTextBox" ng-model="model.label" name="dynamic" class="form-control">
    </div>
    <div class="col-lg-5">
        <button type="button" class="btn btn-primary" ng-disabled="!model.label" ng-click="onAddCheckBox()">Submit</button>
    </div>
    <div class="col-lg-12">
        <div class="checkbox col-lg-12" ng-repeat="checkBox in checkBoxes track by $index">
            <input type="checkbox" name="name_{{$index}}" id="name_{{$index}}" ng-model="checkBox.selectedCheckBox" class="filled-in square chk-col-pink ng-pristine ng-untouched ng-valid ng-empty" checked="checked" aria-invalid="false">
            <label for="checkBox.label">{{checkBox.label}}</label>
        </div>
    </div>
</div>

function init() {
    $scope.isEnableTextBox = false;
    $scope.checkBoxes = [];
    $scope.model = {};
}

$scope.onEnable = function onEnable() {
    $scope.isEnableTextBox = true; // Enable text box on Click Plus Icon
};

$scope.onAddCheckBox = function onAddCheckBox() { // On submit button click push the given name into array and empty the text box. Please refer the attached image.
    var _checkBoxModel = angular.copy($scope.model.label);
    $scope.model.label = "";
    $scope.checkBoxes.push({'label': _checkBoxModel, 'selectedCheckBox': true});
};

init();
提交 {{checkBox.label} 函数init(){ $scope.isEnableTextBox=false; $scope.checkbox=[]; $scope.model={}; } $scope.onEnable=函数onEnable(){ $scope.isEnableTextBox=true;//在单击加号图标时启用文本框 }; $scope.onAddCheckBox=函数onAddCheckBox(){//在提交按钮上单击将给定名称推入数组并清空文本框。请参阅所附图像。 var\u checkBoxModel=angular.copy($scope.model.label); $scope.model.label=“”; $scope.checkbox.push({'label':_checkBoxModel,'selectedCheckBox':true}); }; init();

typescript只是一种编程语言。如何做到这一点完全取决于您使用的前端框架/库,例如react、angular、jQuery等。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-我已经提供了重要的部分。我还为他指明了方向,如果需要的话,他可以在那里找到更多的信息。