Jquery 在一页中重复多个Ng
我的index.html页面上有以下代码Jquery 在一页中重复多个Ng,jquery,angularjs,angularjs-ng-repeat,angularjs-ng-click,Jquery,Angularjs,Angularjs Ng Repeat,Angularjs Ng Click,我的index.html页面上有以下代码 <button id="showdogs">Dogs</button> <div ng-repeat="list in cats"> <li>{{list.name}}</li> </div> <script> $scope.cats = [ {name:"cat1"},{name:"cat2"},{name:"cat3"}] $scope.dogs =
<button id="showdogs">Dogs</button>
<div ng-repeat="list in cats">
<li>{{list.name}}</li>
</div>
<script>
$scope.cats = [
{name:"cat1"},{name:"cat2"},{name:"cat3"}]
$scope.dogs = [
{name:"Dog1"},{name:"Dog2"},{name:"Dog3"}]
</script?
狗
{{list.name}
$scope.cats=[
{name:“cat1”},{name:“cat2”},{name:“cat3”}]
$scope.dogs=[
{name:“Dog1”},{name:“Dog2”},{name:“Dog3”}]
您可以使用ng单击
并在那里传递类型,然后在控制器中根据类型填充数据源
<button id="showdogs" ng-click="showItem('dog')">Dogs</button>
$scope.showItem = function(type){
if(type === 'dog'){
$scope.itemList = [{name:"Dog1"},{name:"Dog2"},{name:"Dog3"}];
}
else if(type === 'cat'){
$scope.itemList = [{name:"cat1"},{name:"cat2"},{name:"cat3"}];
}
};
狗
$scope.showItem=函数(类型){
如果(类型=='dog'){
$scope.itemList=[{name:“Dog1”},{name:“Dog2”},{name:“Dog3”}];
}
else if(类型=='cat'){
$scope.itemList=[{name:“cat1”},{name:“cat2”},{name:“cat3”}];
}
};
在html中
<div ng-repeat="item in itemList">
<li>{{item.name}}</li>
</div>
{{item.name}
请参阅。您可以使用ng单击
并在那里传递类型,然后在控制器中根据类型填充数据源
<button id="showdogs" ng-click="showItem('dog')">Dogs</button>
$scope.showItem = function(type){
if(type === 'dog'){
$scope.itemList = [{name:"Dog1"},{name:"Dog2"},{name:"Dog3"}];
}
else if(type === 'cat'){
$scope.itemList = [{name:"cat1"},{name:"cat2"},{name:"cat3"}];
}
};
狗
$scope.showItem=函数(类型){
如果(类型=='dog'){
$scope.itemList=[{name:“Dog1”},{name:“Dog2”},{name:“Dog3”}];
}
else if(类型=='cat'){
$scope.itemList=[{name:“cat1”},{name:“cat2”},{name:“cat3”}];
}
};
在html中
<div ng-repeat="item in itemList">
<li>{{item.name}}</li>
</div>
{{item.name}
请参阅。AngularJS:
您可以按如下方式使用ng show
,并显示列表:
功能控制器($scope){
$scope.displayCats=true;
$scope.displayDogs=false;
$scope.cats=[{name:“cat1”},{name:“cat2”},{name:“cat3”}];
$scope.dogs=[{name:“Dog1”},{name:“Dog2”},{name:“Dog3”}];
$scope.showDogs=函数(){
$scope.displayDogs=true;
$scope.displayCats=false;
};
$scope.showCats=函数(){
$scope.displayDogs=false;
$scope.displayCats=true;
};
}
狗
猫
{{list.name}
{{list.name}
AngularJS:
您可以按如下方式使用ng show
,并显示列表:
功能控制器($scope){
$scope.displayCats=true;
$scope.displayDogs=false;
$scope.cats=[{name:“cat1”},{name:“cat2”},{name:“cat3”}];
$scope.dogs=[{name:“Dog1”},{name:“Dog2”},{name:“Dog3”}];
$scope.showDogs=函数(){
$scope.displayDogs=true;
$scope.displayCats=false;
};
$scope.showCats=函数(){
$scope.displayDogs=false;
$scope.displayCats=true;
};
}
狗
猫
{{list.name}
{{list.name}
你的问题不清楚。你的问题不清楚。我发现angularjs方法很简单。我想在pageload上显示猫列表。怎么做?我发现angularjs方法很简单。我想在pageload上显示猫列表。怎么做?这就是我需要的。谢谢这是我需要的。谢谢你