How to populate data into html in my case? - javascript

I am trying to populate data into the html page using Angular framework.
I want to add data to existing accordion element
<div ng-controller="Ctrl">
<accordion id='accordion' close-others="false">
<accordion-group is-open="false">
<accordion-heading >
<h2>{{heading}}</h2>
</accordion-heading>
<div>
<div>
{{data}}
</div>
</div>
</accordion-group>
</accordion>
<accordion>
....more
</accordion>
multiple accordions here...
</div>
I am not sure how to add more accordion dynamically. Can anyone help me about it? Thanks a lot!

There is a lot of trick you can do, like using ng-show or ng-hide for example, and have all the accordion all ready write on the page, or a ng-repaet with various accordion inside, but take care of the space in the page.
If i Have understand your problem you can set a variable in that way var data={value:'something',show:'true'} and bind the ng-show parameter to the data show, at least you can do an array of data with the show value, there is an infinite type of solution.
With a plunker or a fiddle it could be easier to help, but i hope my answer could help you anyway.

Related

Create a base component to be reused when creating new components

I'm putting together an application in which there are many modals. As I do not want to repeat the code of the modal, I want to assemble a base component that has the minimum structure and then with that structure to be able to assemble the different modals and to carry what I need inside (form, text, images)
An example of what I am looking to do
<app-modal-base>
<app-form></app-form>
<app-modal-base>
I hope you understand what I'm looking for. In case you can not, someone found an alternative solution?
Thanks
In your base modal template, include the <ng-content></ng-content> tag. When you display your modal, you can use it as follows:
<Modal>
<div id="mydiv">
<p> Simple paragraph </p>
<form>...</form>
</div>
</Modal>
The modal will include what you have included between the <Modal></Modal> tags at the place where the <ng-content></ng-content> tags are in the template for the base modal component. It would look like:
template: `
<div id="closeButton"></div>
<ng-content></ng-content>
`
This information is gathered from this source, and I can't seem to find official docs about this. You might have to try it out.

Render HTML Tag Vue.js

I am trying to add a render a template using the push mutation method. I want to push a section component, but instead of the template content I get the raw output of <vsection></vsection'. Can anyone help me render the actual template content and not the raw tags? I included a jsbin below.
http://jsbin.com/wurofatuve/1/edit?html,js,output
You're thinking about this a little oddly. What I think you'd be better off doing is putting a v-for on a <vsection> component.
<vsection v-for="section in sections">
{{ section.content }}
</vsection>
This way, when you push content to sections it'll out put another one. You'll also have to adjust your section component so you can use the content.
<template id="section-template">
<div class="section">
<slot></slot>
</div>
</template>
Here it is working like I think you want: http://jsbin.com/suhadidobe/1/edit?html,js,output

How to display an element with ng-show based on AngularJS Bootstrap UI Accordion state?

I've got a few dynamic accordions which based on $resource like so:
$scope.categories = $resource.query() // Written as such for simplicity sake
Then in my template I've got the following:
<accordion-group ng-repeat="category in categories" is-open="$first">
<accordion-heading>
<button ng-show="IDontKnow">...</button>
...
</accordion-heading>
</accordion>
With the above, I get my first open by default which is what I want, however I'd like to display the button above only if the accordion is open. Because $first is special variable from ng-repeat I can't change it. I've tried to use isOpen like so:
<button ng-show="category.isOpen">...</button>
But that didn't work either. How can I achieve this? Please bear in mind the accordions are based on dynamic content.
Many thanks in advance.
please see here http://plnkr.co/edit/rv6esLxJuE6NLlxwhZkh?p=preview
you can use ng-init ie: ng-init="category.isOpen=$first"
HTML:
<accordion close-others="oneAtATime">
<accordion-group ng-repeat="category in categories" is-open="category.isOpen" ng-init="category.isOpen=$first">
<accordion-heading>
I can have markup, too!
<button ng-show="category.isOpen">I'm the button</button>
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
</accordion>

In AngularJS how can I create a new ngController dynamically?

I'm trying to create new ngControllers on the fly, is this possible? I'm not writing it into the template with a ngRepeat or anything, since the user might never create an instance of a certain ngController.
Here's an example of my current template:
<div ng-controller="ViewUsers">
<div class="viewUsersList">
<table>
<tr class="userRow" ng-click="viewUser(user.user_id)" ng-repeat="user in users">
<td>{{user.first_name}} {{user.last_name}}
<br />{{user.phone}}
</td>
</tr>
</table>
</div>
</div>
So far it works great. When the user clicks a .userRow it calls viewUser(ID). The problem is here:
I want to create a new block of code like this:
<div ng-controller="UserDetail">
{{first_name}}
</div>
And append this to the DOM.
So if they click on Bobby and Sally, two UserDetail controller objects would be added to the DOM and work accordingly. (Ideally, I'd like to pass in the data-bound user model, but that's for later).
I tried a ghetto version in JSBin, but I'd rather not use JQuery if possible:
http://jsbin.com/EdOteTav/2/edit
Can anyone shine some light on this? Thanks in advance
I would change the code little bit and use directive instead of controller. See this simple and quick example in jsfiddle.
The directive would handle the click events and display whatever you want to display on the DOM. You can get the full user object from scope.user inside the directive.

AngularJS - Is it possible to use ng-repeat to render HTML values?

I'm using AngularJS with a third party service that generates html responses. I want to use ng-repeat to render the HTML responses as a list, however Angular renders it as text.
Is it possible to use ng-repeat to render HTML property?
I've created this jsFiddle to demonstrate my issue.
http://jsfiddle.net/DrtNc/1/
I think using ng-bind-html-unsafe will get you what you need.
<div ng:repeat="item in items" ng-bind-html-unsafe="item.html"></div>
Here's a working fiddle: http://jsfiddle.net/nfreitas/aHfAp/
Documentation for the directive can be found here: http://docs.angularjs.org/api/ng.directive:ngBindHtmlUnsafe
The way I achieved this is by ng-bind-html inside the ng-repeat;
<div ng-repeat="comment in comments">
<div ng-bind-html="comment.content"></div>
</div>
Hope this helps someone!
item.html will always be interpreted as text. you have to convert it to html explicitly. click here
I have added a render function which will convert each string to html.

Categories

Resources