我試圖在每個按鈕點擊動態添加li元素。但是新的li元素沒有被創建。我試圖用ng-repeat來達到同樣的效果。 下面是我的代碼Angularjs在按鈕點擊動態添加li元素
HTML代碼
<div data-ng-app="myApp" data-ng-controller="TestController" >
<div ng-show="showQuerydiv" id="qscompid" style="margin-left:170px;margin-top:90px">
<div class="btn-group" id="buttonOptions" style="width: 100%; position:absolute;">
<a href="#" class="btn btn-primary" ng-click="openQuerydiv('query')">Query</a>
<a href="#" class="btn btn-primary" ng-click="openQuerydiv('script')">Script</a>
<a href="#" class="btn btn-primary" ng-click="openQuerydiv('compare')">Comp</a>
<div style="float: right; width: 30%">
<a href="#operationDetailInfo" class="glyphicon glyphicon-info-sign" data-toggle="collapse" style="float: left;" title="Info"></a>
<div id="operationDetailInfo" class="collapse" style="width: 95%; float: left;">
</div>
</div>
<br>
<div id="sqlQueryDiv" ng-show="isShow" style="width: 100%;margin-top: 30px;margin-left: -170px;">
<ul class="nav nav-tabs" role="tablist" id="queryULId" style="width: 1140px;height: 39px;">
<li class="active" ng-repeat="tabs in tabcount">
<a href="#queryTab"+{{tabCount}} role="tab" data-toggle="tab">
{{tabName}}{{tabCount}}
</a>
<span class="close" style="font-size: 12px; position: absolute; margin-left: 85%; margin-top: -25%; cursor: pointer;">X</span>
</li>
</ul>
<div class="tab-content" style="width:1177px;height: 225px;">
</div>
</div>
</div>
</div>
角的js代碼
var app = angular.module('myApp', []);
app.controller('TestController', function($scope){
console.log('Going for execution ');
$scope.tabCount = 0 ;
$scope.showQuerydiv = true;
$scope.isShow = false;
$scope.list =" " ;
$scope.openQuerydiv = function(parameter)
{
alert("inside the openqueryDiv") ;
if(parameter == 'query')
{
alert("inside the openquerydiv" + parameter);
$scope.isShow=true;
$scope.tabName='SQL Query';
$scope.tabCount++ ;
}
}
});
在上面的代碼,上查詢按鈕,第一時間,該選項卡點擊被創建。在第二次點擊時,相同的選項卡被修改而不是創建新的選項卡。你能否讓我知道如何實現同樣的目標。點擊每個按鈕,我想要創建一個新的選項卡。
任何幫助,這是非常感謝。
我看不到任何'ng-repeat'你的html – svarog