eagle eagle -4 years ago 57
AngularJS Question

How to create html code when click button?

My code html code as the following :

<comp:Tab runat="server" ID="AddhocKPIs" ClientIDMode="Static" name="AddhocKPIs" label="Add Ad hoc KPI">
<table class="kpi-editor-layout">
<tr>
<td class="layout-column" style="border: 1px solid #eeeeee;">
<table class="table table-striped">
<tbody>
<tr style="display: table-row"></tr>
<tr style="display: table-row">
<th>KPI Name</th>
<td class="sep">:</td>
<td>
<input type="text" class="form-control" id="" maxlength="30" />
</td>
</tr>
<tr style="display: table-row">
<th>KPI Type</th>
<td class="sep">:</td>
<td>
<select class="form-control" id="">
<option value="0">Numeric</option>
<option value="1">Percentage</option>
<option value="2">NonNumeric</option>
</select>
</td>
</tr>
<tr style="display: table-row">
<th>Precision</th>
<td class="sep">:</td>
<td>
<input type="text" class="form-control" id="" />
</td>
</tr>
</tbody>
</table>
</td>
<td class="layout-column" style="border: 1px solid #eeeeee;">
<table class="table table-striped">
<tbody>
<tr style="display: table-row"></tr>
<tr>
<th>QRY</th>
<td class="sep">:</td>
<td title="Query">
<select class="form-control" id="PmTabQueries">
<option value="{{QRY.Name}}" ng-repeat="QRY in PmTabQueries">{{QRY.Name}} ({{QRY.QRY}})</option>
</select>
</td>
</tr>
<tr>
<td class="formula" colspan="3">
<div id="" class="FormulaEditor">
<div class="head form-inline" style="margin-bottom: 5px;">
<input type="text" placeholder="search" class="ui-autocomplete-input form-control clearfix" autocomplete="off" style="width: calc(100% - 45px);" />
<button title="Zoom In" id="zoomIn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only zoomInOut" role="button" ng-click="zoomInOutQRY()">
<span class="ui-button-icon-primary ui-icon ui-icon-zoomin"></span>
<span class="ui-button-text">Zoom In</span>
</button>
<button title="Zoom Out" id="zoomOut" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only zoomInOut" role="button" ng-click="zoomInOutQRY()">
<span class="ui-button-icon-primary ui-icon ui-icon-zoomout"></span>
<span class="ui-button-text">Zoom Out</span>
</button>
<div class="body" id="formulaContainer">
</div>
</div>
<div class="body">
<iframe class="ui-widget-content formula" frameborder="0"></iframe>
<iframe class="ui-widget-content formula-complete-popup" frameborder="0" style="display: none;"></iframe>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</comp:Tab>


and I have a button. Code like this :

<button id="UxAddHocKPIs" class="ui-state-default inlineIconAddHoc" ng-click="addHocKPIs()">
<span class="ui-button-text">Add new Ad hoc KPI</span>
</button>


and this is my .js code (ng-click) :

$scope.addHocKPIs = function () {
console.log("a");
}


I want to something like this: When I click addHocKPIs button, I should create html code again.

I mean,enter image description here

Can you help me please ?

Answer Source

Check plnkr for complete code.

 var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.current = 0;
  $scope.addHocKPIs = function () {
                    $scope.repeatTable.push('test'+$scope.current+1);
                };

  $scope.repeatTable= [];
   $scope.repeatTable.push('test'+$scope.current+1);
});

HTML:

<table class="kpi-editor-layout" ng-repeat="tab in repeatTable track by $index">
                                <tr>
                                    <td class="layout-column" style="border: 1px solid #eeeeee;">
                                        <table class="table table-striped">
                                            <tbody>
                                                <tr style="display: table-row"></tr>
                                                <tr style="display: table-row">
                                                    <th>KPI Name</th>
                                                    <td class="sep">:</td>
                                                    <td>
                                                        <input type="text" class="form-control" id="" maxlength="30" />
                                                    </td>
                                                </tr>
                                                <tr style="display: table-row">
                                                    <th>KPI Type</th>
                                                    <td class="sep">:</td>
                                                    <td>
                                                        <select class="form-control" id="">
                                                            <option value="0">Numeric</option>
                                                            <option value="1">Percentage</option>
                                                            <option value="2">NonNumeric</option>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr style="display: table-row">
                                                    <th>Precision</th>
                                                    <td class="sep">:</td>
                                                    <td>
                                                        <input type="text" class="form-control" id="" />
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                    <td class="layout-column" style="border: 1px solid #eeeeee;">
                                        <table class="table table-striped">
                                            <tbody>
                                                <tr style="display: table-row"></tr>
                                                <tr>
                                                    <th>QRY</th>
                                                    <td class="sep">:</td>
                                                    <td title="Query">
                                                        <select class="form-control" id="PmTabQueries">
                                                            <option value="{{QRY.Name}}" ng-repeat="QRY in PmTabQueries">{{QRY.Name}} ({{QRY.QRY}})</option>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="formula" colspan="3">
                                                        <div id="" class="FormulaEditor">
                                                            <div class="head form-inline" style="margin-bottom: 5px;">
                                                                <input type="text" placeholder="search" class="ui-autocomplete-input form-control clearfix" autocomplete="off" style="width: calc(100% - 45px);" />
                                                                <button title="Zoom In" id="zoomIn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only zoomInOut" role="button" ng-click="zoomInOutQRY()">
                                                                    <span class="ui-button-icon-primary ui-icon ui-icon-zoomin"></span>
                                                                    <span class="ui-button-text">Zoom In</span>
                                                                </button>
                                                                <button title="Zoom Out" id="zoomOut" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only zoomInOut" role="button" ng-click="zoomInOutQRY()">
                                                                    <span class="ui-button-icon-primary ui-icon ui-icon-zoomout"></span>
                                                                    <span class="ui-button-text">Zoom Out</span>
                                                                </button>
                                                                <div class="body" id="formulaContainer">
                                                                </div>
                                                            </div>
                                                            <div class="body">
                                                                <iframe class="ui-widget-content formula" frameborder="0"></iframe>
                                                                <iframe class="ui-widget-content formula-complete-popup" frameborder="0" style="display: none;"></iframe>
                                                            </div>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            </table>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download