admin管理员组文章数量:1278825
I'm using Ionic framework and Angular js to build a news app !
I'm showing the news on ion-slide-box using ng-repeat here is an example :
<ion-slide-box on-slide-changed="slideHasChanged($index)" show-pager="true" ng-if="items" >
<ion-slide ng-repeat="i in items">
<h4>{{i.name}}</h4>
<p>{{i.gender}}</p>
<p>{{i.age}}</p>
</div>
</ion-slide>
</ion-slide-box>
I want to insert data dynamically to my ion-slide-box for each slide so I'm using this code :
$scope.slideHasChanged = function(index) {
$scope.items.push("{name:'John', age:25, gender:'boy'}");
}
but this doesn't seem to work right so if you have an idea on how can I reslove this that would be great :)
here is CODEPEN + CODE
I'm using Ionic framework and Angular js to build a news app !
I'm showing the news on ion-slide-box using ng-repeat here is an example :
<ion-slide-box on-slide-changed="slideHasChanged($index)" show-pager="true" ng-if="items" >
<ion-slide ng-repeat="i in items">
<h4>{{i.name}}</h4>
<p>{{i.gender}}</p>
<p>{{i.age}}</p>
</div>
</ion-slide>
</ion-slide-box>
I want to insert data dynamically to my ion-slide-box for each slide so I'm using this code :
$scope.slideHasChanged = function(index) {
$scope.items.push("{name:'John', age:25, gender:'boy'}");
}
but this doesn't seem to work right so if you have an idea on how can I reslove this that would be great :)
here is CODEPEN + CODE
Share Improve this question asked Jun 16, 2015 at 9:50 Stranger B.Stranger B. 9,37422 gold badges75 silver badges111 bronze badges2 Answers
Reset to default 8You need to call the update method on $ionicSlideBoxDelegate. (Also, @mark-veenstra is correct, you're pushing a string and not an object).
angular.module('ionicApp', ['ionic'])
.controller('MyCtrl', function($scope, $ionicSlideBoxDelegate) {
$scope.items=friends;
$scope.slideHasChanged = function() {
$scope.items.push({name:'John', age:25, gender:'boy'});
$ionicSlideBoxDelegate.update();
};
});
var friends = [
{name:'John', age:25, gender:'boy'},
{name:'Jessie', age:30, gender:'girl'},
{name:'Johanna', age:28, gender:'girl'},
{name:'Joy', age:15, gender:'girl'},
{name:'Mary', age:28, gender:'girl'}
];
Also, make sure that you give your slider a height:
.slider {
height: 200px;
}
I'm not pletely sure what you are trying to achieve, but if you want this code to work, just change:
$scope.items.push("{name:'John', age:25, gender:'boy'}");
To:
$scope.items.push({name:'John', age:25, gender:'boy'});
本文标签: javascriptHow to insert data dynamically to ionslidebox Angularjs IonicStack Overflow
版权声明:本文标题:javascript - How to insert data dynamically to ion-slide-box Angularjs Ionic - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741223221a2361368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论