Im trying to call a function inside ng-init using the result of ng-repeat but the only image displayed is the last image that was pass to the scope variable.
Any tips or suggestion if im doing this correctly?
Template
<ion-item ng-repeat="feed in feeds" ng-if=fbfeed.message ng-init='addAttachment(feed.id)'>
<div class="list card">
<div class="item item-body">
<img src="{{attachment.media.image.src}}">
</div>
</div>
</ion-item>
Controller
$scope.addAttachment = function (postId) {
var attachmentData = MediaManager.getAttachments( postId );
attachmentData.then(function(result) {
if (result.data.length) {
$scope.attachment = result.data[0];
}
});
};
You need to add the attachment
field with all the objects . so add that to the object feed
.
You can pass the feed id and assign the corresponding image in the function.
HTML
<ion-item ng-repeat="feed in feeds" ng-if=fbfeed.message ng-init='addAttachment(feed)'>
<div class="list card">
<div class="item item-body">
<img src="{{feed.attachment.media.image.src}}">
</div>
</div>
</ion-item>
Controller:
$scope.addAttachment = function (feed) {
var attachmentData = MediaManager.getAttachments( feed.postId );
attachmentData.then(function(result) {
if (result.data.length) {
feed.attachment = result.data[0];
}
});
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.