I am working in angularjs application, i have used ng-repeat in my application but i need to insert images in between every ng-repeat loop dynamically.
Is it possible to inject image inbetween every ng-repeat.
sample xml file
`<?xml version='1.0' encoding='UTF-8' ?>
<revista>
<notas>
<banner>No</banner>
<bannerFuente></bannerFuente>
<bannerURL></bannerURL>
<copete>Editorial</copete>
<titulo>Se armó en grande</titulo>
<seccion>Opinión</seccion>
</notas>
<notas>
<banner>No</banner>
<bannerFuente></bannerFuente>
<bannerURL></bannerURL>
<copete>Perfiles de clientes</copete>
<titulo>¿Quién se llevó mi negocio?</titulo>
<seccion>Opinión</seccion>
</notas>
<notas>
<banner>No</banner>
<bannerFuente></bannerFuente>
<bannerURL></bannerURL>
<copete>Gestión empresarial</copete>
<titulo>Gestión para pequeños negocios</titulo>
<seccion>Opinión</seccion>
</notas>
</revista>`
js file
$http.get('sample.xml').then(function(response)
{
var dom = response.data;
$scope.posts = dom.revista.notas;
})
html file with ng-repeat and swiper
<div class="swiper-container" ng-controller='MainCtrl'>
<div class="swiper-wrapper">
<div class="swiper-slide" ng-repeat="key in posts">
<div class="mag_content_wrap con_style1">
<div class="cls_favorite_sec editorial_page1">
<h2>{{key.seccion}}</h2>
</div>
<div class="cls_favorite_sec editorial_page">
<div class="cls_inner1 img_r">
<p class="img_con">
<img src="Imagenes/{{key.imagen}}" />
</p>
</div>
<div class="cls_inner2 editorial_page2">
<h2>{{key.copete}}</h2>
<h3>{{key.titulo}}</h3>
</div>
</div>
</div>
</div>
</div>
</div>
In the above code ng-repeat shows three pages properly, but i need to load image inbetween every page after swipe. If i swipe first content it should shows image and if i swipe image it shows second content and vice versa.
Related
I use Grapesjs editor. And now I know only 1 way to store the content.
The situation is the following:
I have Grapesjs block 'About us' which I populate with child cards components. And then I get the content with editor.getHtml() and I may get something like this:
<section class="sect-home-about">
<div class="container">
<div class="title-sect"><h2>Über uns</h2></div>
<div class="about-wrap">
<div class="about-line" id="i94s">
<div class="about-itm">
<div class="about-itm-inner">
<a href="#" class="about-itm-photo"><span class="img-inner-box" id="im8d1">
<img src="/css/img/square.png" alt="base"/>
<img src="/img/about/1.png" alt="" title="" class="main-img"/></span></a>
<div class="about-itm-txt">
<div class="about-itm-name">Andrea</div>
<div class="about-itm-brief">Weit hinten, hinter den Wortbergen, fern der Länder Vokalien
und Konsonantien leben die Blindtexte. Abgeschieden wohnen sie mehr lesen
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
And this I can save to DB and then show on front-end. But I don't want to store useless html. Here the editable items should be .title-sect, .about-itm-name, .about-itm-bries and image data. I would like to store only json data and then display it on front-end with correct html, because html is the same and I know it..
Is there such a solution ?
After your GrapesJS is initialized, inside your event add the following code for getting the JSON data output.
JSON.stringify(editor.getComponents())
Here, Component overrides the toJSON function, hence this works.
"allitems" contains all items for a category that is selected in a combobox. That part of the code working properly.
I have images saved in a database as binary data for each item. When an item is displayed then the image of the item shall be rendered. For doing this I have to save item's ID in ASP .Net controller before rendering, because the "RenderImage" needs the Item's ID. This is done by calling "saveItemId" in AngularJS controller.
But the rendering of the images are very unpredictable. "saveItemId" is called repeatedly but not RenderImage.
There is no problem calling methods/saving ID in AngularJS controller or in ASP .Net MVC controller.
<div dir-paginate="r in allitems | filter:q | itemsPerPage: pageSize" current-page="currentPage" ng-init ='saveItemId(r.ID)' class="ag-fresh">
<div style="float:left">
<div class="col-xs-3">
<div style="width:200px;">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<img src="#Url.Action("RenderImage")" height="84" width="84"/>
<br/>
<h>{{r.Price}}</h>
<p>{{r.Name}}</p>
<button class="btn btn-default add-to-cart" ng-click="AddToCart(r.ID)">Add to cart</button>
{{successTextAlert}}
</div>
</div>
</div>
</div>
</div>
</div>
its seems that RenderImage is a js variable in the controller scope. if its so, its need to be call with brackets, like {{RenderImage}}
Try using 'ng-src' instead 'src' attribute, for the img element as described at
https://docs.angularjs.org/api/ng/directive/ngSrc#!
This works properly:
<img ng-src="data:image/jpeg;base64,{{arrayBufferToBase64(r.InternalImage)}}" height="84" width="84"/>
I Added arrayBufferToBase64 to the angular controller.
I have below div (class name 'sp') which I would like to dynamically create based on the sk from a dataset object.
div code
<div style="" class="swindow">
<div class="sp" style="">
<div class="svis" style="">
<div style="height:95%;width:95%;margin-top:0px;margin-left:5px;">
<chart dsn="dyndata" editable="false" labelled="true"></chart>
</div>
</div>
<div class="sdata" style="">
<div class="stext" style="">Average:78% </div>
</div>
</div>
While searching for similar examples, I came across ng-repeat in Angular js and I thought it might suit for this kind of objective.
But am very new to Angular js and not sure how to assign the data to my dyndata variable dynamically and create new div (class=sp) for each of the given id.
Here is the lookup object
[
{"id":20,"st":[{"label":"Audi","value":10},{"label":"BMW","value":70}]},
{"id":26,"st":[{"label":"Benz","value":40},{"label":"BMW","value":20}]},
{"id":12,"st":[{"label":"AUDI","value":60},{"label":"Tesla","value":70}]},
{"id":57,"st":[{"label":"MZ","value":30},{"label":"Honda","value":40}]}
]
When I input the id's as a set [12,26,57] - Three divs (each for #sp) should get created one for each of ids. In those, each div should have the dyndata assigned with the respective 'st' from above javascript object.
I could create div's in jquery using .append function to the container (#swindow) each time when I need. But am not sure how to assign sk as input to dyndata dataset for each div that gets created.
Could you please share how this can be achieved using Angular js ?
Here is the angular js code I used -
<script>
var app = angular.module('ExampleApp', ['ui.plot']);
app.controller('PlotCtrl', function ($scope) {
$scope.dyndata={};
});
</script>
I'm not exactly sure what you're trying to do but I think it should look something like this. Here is a plnkr..
Controller:
app.controller('PlotCtrl', function($scope) {
$scope.items = [
{"id":20,"st":[{"label":"Audi","value":10},{"label":"BMW","value":70}]},
{"id":26,"st":[{"label":"Benz","value":40},{"label":"BMW","value":20}]},
{"id":12,"st":[{"label":"AUDI","value":60},{"label":"Tesla","value":70}]},
{"id":57,"st":[{"label":"MZ","value":30},{"label":"Honda","value":40}]}
]
});
HTML:
<body ng-controller="PlotCtrl">
<div style="" class="swindow">
<div class="sp" style="" ng-repeat="item in items">
<div class="svis" style="">
<strong>{{item.id}}:</strong>
<div>-{{item.st[0].label}}</div>
<div>-{{item.st[1].label}}</div>
<div style="height:95%;width:95%;margin-top:0px;margin-left:5px;">
<chart dsn="dyndata" editable="false" labelled="true"></chart>
</div>
</div>
<div class="sdata" style="">
<div class="stext" style="">Average:78% </div>
<br>
</div>
</div>
</div>
</body>
I have this simple audio for mediaElement.js which works with normal HTML/Js but does not work with angularjs. The Media player is shown just fine but clicking play button does not work.
<div class="col-md-6">
<div class="alert alert" ng-repeat="media in medias">
<h3>{{media.title}}</h3>
<p>{{media.summary}}</p>
<audio id="{{media.filename}}" src="http://danosongs.com/music/danosongs.com-orb-of-envisage.mp3" type="audio/mp3" controls="controls">
</div>
</div>
<script>
// using jQuery
$('video,audio').mediaelementplayer(/* Options */);
</script>
![enter image description here][1]
I found the problem thanks to #Biswanath. I was loading Mediaelement before Angular finished loading the elements. So I had to call it when all elements are loaded. Googling I found the solution here and here is my HTML codes
<div class="alert alert" ng-repeat="media in medias" ng-init="$last ? loadMediaElement() : false">
Then in my controller scope, I register Javascript function which bootstraps MediaElementjs, since ng-repeat is done
$scope.loadMediaElement = function()
{
$('video,audio').mediaelementplayer(/* Options */);
};
So I followed this guide so I could have a nav bar on every page: http://tomaszdziurko.pl/2013/02/twitter-bootstrap-navbar-angularjs-component/
And it was working, until I created a separate controller to populate my bootstrap carousel. The thing is, my ng-repeat works fine, but when it does I can't see my navbar on that page. I can see it just fine on other pages. I believe this is a scoping issue, but I am not sure where.
This is what I have in the main body of this page:
<body>
<reusable-navbar></reusable-navbar>
<!-- Carousel Start -->
<div id="main-carousel" class="carousel slide container" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<!--Must set this by hand-->
<div class="item active">
<img alt="" src="../Revamp/Images/carousel/1.jpg">
</div>
<!--Repeat through the rest-->
<div ng-controller="carouselPhotoController">
<div class="item" ng-repeat="source in source">
<img alt="" ng-src="{{source.source}}">
</div>
</div>
</div>
</div>
And my controller looks like this:
var carouselPhotoController=angular.module("revampApp", []);
carouselPhotoController.controller("carouselPhotoController", function($scope, $http){
$http.get('../Revamp/Images/carousel/photos.json').success(function(photos){
//Carousel photos
$scope.source = photos;
})
});
And the directive is identical to the one in that walk through, just with a different template. So how to I get it so my nav bar will show up AND I can use ng-repeat?
Make sure you are not recreating the app.
This creates a new app:
var carouselPhotoController=angular.module("revampApp", []);
But this only accesses an app already created (note the absence of the second parameter):
var carouselPhotoController=angular.module("revampApp");
Change the above line and it should work.