How to query critical JSON into ionic - angularjs

I received the JSON response from the server mentioned below.
{
"employeeId": null,
"id": "DB06442E-2993-4FE8-B496-5A0CF61C8342",
"message": null,
"objects": [
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1000
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:14AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Automatic Cold Cranking Simulator"
},
{
"Key": "CallCategory",
"Value": "Corrective Maintenance"
}
],
"Type": 8
},
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1000
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:20AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Auto Mini Pour Point Tester "
},
{
"Key": "CallCategory",
"Value": "Preventive Maintenance"
}
],
"Type": 8
},
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1000
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:23AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Balance - Citizon CX 220"
},
{
"Key": "CallCategory",
"Value": "Calibration"
}
],
"Type": 8
},
{
"Children": [],
"Fields": [
{
"Key": "CallID",
"Value": 1001
},
{
"Key": "CallDate",
"Value": "Sep 9 2016 10:26AM"
},
{
"Key": "ClientName",
"Value": ""
},
{
"Key": "AssetName",
"Value": "Others"
},
{
"Key": "CallCategory",
"Value": "Installation"
}
],
"Type": 8
}
],
"success": true
}
Can you please explain me bit more as per my json structure.
myhtml.html
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="item in callItems" type="item-text-wrap" ng-click="doTask()">
<h3 style="color:black;">{{item.CallID}}</h3>
<h3 style="color:black;">{{item.CallDate}}</h3>
<p style="color:black;">{{item.ClientName}}</p>
<p style="color:black;">{{item.AssetName}}</p>
<p style="color:black;">{{item.CallCategory}}</p>
</ion-item>
myjs.js
$http.post("http://testCrm.com/GetAllObjects",
{"objectId":null,"objects":null,"searchParams":null,"sessionId":"DB06442E-2993-4FE8-B496-5A0CF61C8342","type":8})
.success(function(data) {
alert("SUCCESS!");
$rootScope.callItems = data;
console.log($rootScope.callItems);
})
.error(function(data) {
alert("ERROR");
alert(data);
});
As per my code I can able to get the response But How can i parse the value in View ?

you can follow this also
<div ng-repeat="(key, value) in item.Fields">
<h3 style="color:black;"> {{value.Value}}</h3>
</div>
<button ng-click=something($index,item.Fields[0].Value)>check it</button>
</div>
js
add the below function and see u will get a alert with index
$scope.something=function(a,b){
alert(a);//alerts index
alert(b);//alerts CaalID of that index
}
working codepen
new requirments

this might not be the best solution but it's a working demo. i think you need to change the json object structure again and re create it according to your requirement.
<div ng-repeat="item in callItems.objects">
<div ng-repeat="fi in item" >
<div ng-repeat="kk in fi">
<h3 style="color:black;" ng-if="kk.Key == 'CallID'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'CallDate'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'ClientName'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'AssetName'">{{kk.Value}}</h3>
<h3 style="color:black;" ng-if="kk.Key == 'CallCategory'">{{kk.Value}}</h3>
</div>
</div>

Related

vuejs bind object data to screen that will end up looping

I have a challenge, i am trying to bind my object data on the screen that will eventually loop when there are more items added. How do i make the brackets dissapear during render Any help please
new Vue({
el: "#app",
data: {
box: [
{
"Title": "Welcome!",
"Topics": [
{
"Title": "Overview of Courses"
},
{
"Title": "tETS 1"
},
{
"Title": "TEST 3"
},
{
"Title": "TEST 4"
},
{
"Title": "TEST 5"
}
],
"Description": {
"Text": "",
"Html": ""
}
},
{
"Title": "Module 500: test test",
"Modules": [
{
"Title": "GRADE WORK",
"Modules": [],
"Topics": [
{
"Title": "1.1 [Assignments] SET UP",
"Description": {
"Html": "<div class=\"container\">\n<h2>Description</h2>\n<p>Pick two differently shaped objects that are white.</div>"
}
}
],
"LastModifiedDate": "2020-10-30T01:20:30.627Z",
"Description": {
"Text": "",
"Html": ""
}
},
{
"Title": "act gas",
"Modules": [],
"Topics": [
{
"Title": "Introduction"
}
],
"LastModifiedDate": "2020-10-30T01:20:30.780Z",
"Description": {
"Text": "",
"Html": ""
}
}
],
"Topics": [
{
"Title": "Intro"
}
],
"LastModifiedDate": "2020-10-30T01:20:30.273Z",
"Description": {
"Text": "",
"Html": ""
}
}
]
},
methods: {
toggle: function(todo){
todo.done = !todo.done
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<h2>Todos:</h2>
<div v-for="box_data in box" :key="box_data.id">
<strong><span class="text-center bold"> {{ box_data.Title}} </span></strong>
<ul v-for="topics in box_data.Topics" :key="topics.id">
<li> {{ topics }} </li>
</ul>
</div>
</div>
You're currently rendering the entire topics object, but you only need the Title property of that object, so update your string interpolation to render that specific property:
<ul v-for="topics in box_data.Topics" :key="topics.id">
👇
<li> {{ topics.Title }} </li>
</ul>
new Vue({
el: "#app",
data: {
box: [
{
"Title": "Welcome!",
"Topics": [
{
"Title": "Overview of Courses"
},
{
"Title": "tETS 1"
},
{
"Title": "TEST 3"
},
{
"Title": "TEST 4"
},
{
"Title": "TEST 5"
}
],
"Description": {
"Text": "",
"Html": ""
}
},
{
"Title": "Module 500: test test",
"Modules": [
{
"Title": "GRADE WORK",
"Modules": [],
"Topics": [
{
"Title": "1.1 [Assignments] SET UP",
"Description": {
"Html": "<div class=\"container\">\n<h2>Description</h2>\n<p>Pick two differently shaped objects that are white.</div>"
}
}
],
"LastModifiedDate": "2020-10-30T01:20:30.627Z",
"Description": {
"Text": "",
"Html": ""
}
},
{
"Title": "act gas",
"Modules": [],
"Topics": [
{
"Title": "Introduction"
}
],
"LastModifiedDate": "2020-10-30T01:20:30.780Z",
"Description": {
"Text": "",
"Html": ""
}
}
],
"Topics": [
{
"Title": "Intro"
}
],
"LastModifiedDate": "2020-10-30T01:20:30.273Z",
"Description": {
"Text": "",
"Html": ""
}
}
]
},
methods: {
toggle: function(todo){
todo.done = !todo.done
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<h2>Todos:</h2>
<div v-for="box_data in box" :key="box_data.id">
<strong><span class="text-center bold"> {{ box_data.Title}} </span></strong>
<ul v-for="topics in box_data.Topics" :key="topics.id">
<li> {{ topics.Title }} </li>
</ul>
</div>
</div>

I need a helper function to loop through complex object arrays with ngFor

I'm working on setting up a loop in angular and I'm quite new to this. Normally I'd be able to do it no problem but since I was given a weird data object to work with I'm terribly stuck. My code is as follows.
So far I can get the list from "children" at the top of the object but I cant go any further.
Here is my data
{
"type": "categoryGroup",
"children": [
"Apples",
"Bananas",
"Oranges"
],
"Apples": {
"type": "categorySubgroup",
"children": [
"Golden Delicious",
"Granny Smith",
"Macintosh"
],
"Golden Delicious": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
},
"Granny Smith": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
},
"Macintosh": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
}
},
"Bananas": {
"type": "categorySubgroup",
"children": [
"Lady's Finger",
"Cavendish Bananas"
],
"Lady's Finger": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
},
"Cavendish Bananas": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
}
},
"Oranges": {
"type": "categorySubgroup",
"children": [
"Blood Orange"
],
"Blood Orange": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
}
}
}
Here is the HTML part of my code (which is failing miserably)
<div class="col-md-12" *ngFor="let category of fruit.categories.children">
<div class="card">
<div class="card__header">
<h4 class="card__title">{{ category }}</h4>
</div>
<div class="card__body">
<div class="row">
<div class="col-md-4" *ngFor="let categoryGroup of category.children">
<div class="subheader">{{ categoryGroup }}</div>
<div>
<ul class="resource-list" *ngFor="let categoryItem of categoryGroup.articles">
<li>{{ categoryItem.name }}</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
I would like some help looping down the object arrays, maybe as a helper function using the "children" array. Any thoughts or help would be greatly appreciated. Thanks!
Try out the following code, please.
<div class="col-md-12" *ngFor="let category of fruit.children">
<div class="card">
<div class="card__header">
<h4 class="card__title">{{ category }}</h4>
</div>
<div class="card__body">
<div class="row">
<div class="col-md-4" *ngFor="let categoryGroup of fruit[category].children">
<div class="subheader">{{ categoryGroup }}</div>
<div>
<ul class="resource-list" *ngFor="let categoryItem of fruit[category].articles">
<li>{{ categoryItem.name }}</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
You could get at the data using methods in the component to keep things quite clear. Here's an example object that could be used for testing:
export const data = {
"type": "categoryGroup",
"children": [
"Apples",
"Bananas",
"Oranges"
],
"Apples": {
"type": "categorySubgroup",
"children": [
"Golden Delicious",
"Granny Smith",
"Macintosh"
],
"Golden Delicious": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
},
"Granny Smith": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
},
"Macintosh": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
}
},
"Bananas": {
"type": "categorySubgroup",
"children": [
"Lady's Finger",
"Cavendish Bananas"
],
"Lady's Finger": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
},
"Cavendish Bananas": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
}
},
"Oranges": {
"type": "categorySubgroup",
"children": [
"Blood Orange"
],
"Blood Orange": {
"type": "articleList",
"articles": [
{
"key": "article-1",
"name": "Article 1"
},
{
"key": "article-2",
"name": "Article 2"
}
]
}
}
}
Now, we could import this data and create some getters (in app.component.ts for example):
import { Component } from '#angular/core'
import { data } from './data'
#Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
data = data
getFruits() {
return data.children
}
getFruit(fruit: string) {
return data[fruit]
}
getVarieties(fruit) {
return data[fruit].children
}
getVariety(fruit, variety) {
return data[fruit][variety]
}
getArticles(fruit, variety) {
return data[fruit][variety].articles
}
getArticle(fruit, variety, article) {
return data[fruit][variety][article]
}
}
In the template, the properties could now be used like this:
<h1>Fruit Data</h1>
<p><span class="key">type:</span> {{ data.type }}</p>
<p><span class="key">children:</span> {{ data.children }}</p>
<hr>
<div class="fruit" *ngFor="let fruit of getFruits()">
<h2>{{ fruit }}</h2>
<p><span class="key">type:</span> {{ getFruit(fruit).type }}</p>
<p><span class="key">children:</span> {{ getFruit(fruit).children }}</p>
<div class="variety" *ngFor="let variety of getVarieties(fruit)">
<h3>{{ variety }}</h3>
<p><span class="key">type:</span> {{ getVariety(fruit, variety).type }}</p>
<p><span class="key">articles:</span> {{ getArticles(fruit, variety) | json }}</p>
<div class="article" *ngFor="let article of getArticles(fruit, variety)">
<p><span class="key">key:</span> {{ article.key }}</p>
<p><span class="key">name:</span> {{ article.name }}</p>
</div>
</div>
</div>

Multi-dimensional arrays in Mandrill with handlebars

I'm trying to loop through a multi-dimensional array to get properties of products that are part of line items. They look basically like this: (I did a json_encode so it would be easier to read)
[{
"rcpt": "email#email.com",
"vars": [{
"name": "SYSTEM",
"content": "Bikes"
}, {
"name": "CUSTOMERSERVICE",
"content": "(855-553-4889)"
}, {
"name": "IMAGE",
"content": "http:\/\/www.url.com\/assets\/images\/chicago\/email\/dear_member.jpg"
}, {
"name": "LINKCOLOR",
"content": "#3db7e4"
}, {
"name": "FACEBOOK",
"content": "Bikes"
}, {
"name": "TWITTER",
"content": "Bikes"
}, {
"name": "INSTAGRAM",
"content": "Bikes"
}, {
"name": "CLOSING",
"content": "Greetings"
}, {
"name": "item",
"content": [{
"lineItem": 1,
"id": "3",
"name": "24-Hour Pass Gift Certificate",
"quantity": 2,
"nameShort": "24-Hour",
"type": "Gift Certificate",
"image": "24hour_blank.jpg",
"price": "9.95",
"total": "19.90",
"taxable": false,
"giftCertificates": {
"3204": {
"id": "3204",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
},
"3205": {
"id": "3205",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
}
}
}, {
"lineItem": 2,
"id": "1",
"name": "Annual Membership Gift Certificate",
"quantity": 2,
"nameShort": "Annual",
"type": "Gift Certificate",
"image": "annual_blank.jpg",
"price": "75.00",
"total": "150.00",
"taxable": false,
"giftCertificates": {
"892": {
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
"893": {
"id": "893",
"redemptionNumber": "xxxxx",
"type": "Annual"
}
}
}]
}, {
"name": "orderID",
"content": 1220
}, {
"name": "giftMessage",
"content": false
}, {
"name": "email",
"content": "email#email.com"
}, {
"name": "transactionDate",
"content": "12\/23\/2015"
}, {
"name": "transactionTime",
"content": "12:21 pm"
}, {
"name": "salesTaxTotal",
"content": 0
}, {
"name": "salesTaxRatePercent",
"content": "6.250"
}, {
"name": "TransactionAmount",
"content": "169.90"
}, {
"name": "account_number",
"content": "XXXX1111"
}, {
"name": "card_type",
"content": "Visa"
}, {
"name": "firstName",
"content": "tetete"
}, {
"name": "lastName",
"content": "tethuhhu"
}, {
"name": "address",
"content": "295 Place St"
}, {
"name": "city",
"content": "Brooklyn"
}, {
"name": "state",
"content": "NY"
}, {
"name": "zip",
"content": "11238"
}, {
"name": "country",
"content": "US"
}, {
"name": "phone",
"content": "8888888888"
}, {
"name": "transactionId",
"content": "xxxxxx"
}, {
"name": "shipToFirstName",
"content": "tetete"
}, {
"name": "shipToLastName",
"content": "tethuhhu"
}, {
"name": "shipToAaddress",
"content": "295 Place St"
}, {
"name": "shipToCity",
"content": "Brooklyn"
}, {
"name": "shipToState",
"content": "NY"
}, {
"name": "shipToZipCode",
"content": "11238"
}, {
"name": "ShipToCountry",
"content": "US"
}, {
"name": "ShipToCountry",
"content": "US"
}]
}]
So I am trying to get a print out of each gift certificate's type and redemption number. When I iterate through {{ giftCertificates }} like this:
{{#each giftCertificates}}
{{type}} {{redemptionNumber}}
{{/each}}
I get one of the line items but not the other. I'm guessing maybe it is being overwritten when it loops through again? But I have also tried to loop through {{ item }} and grab {{ giftCertificates.type }} and {{ giftCertificates.redemptionNumber }} and that does not work either. What is the correct way to get all of these from each line item?
Thanks for your help.
I know this is a very old question, but:
you can use {{this.proprietyName}} to get the type and number:
{{#each giftCertificates}}
{{this.892.type}}
{{/each}}
do not forget to add this to the mandrill message o
"merge": true,
"merge_language": "handlebars",
Also, the data structure is not ideal:
giftCertificates[
{
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
{
"id": "893",
"redemptionNumber": "xxxxxx",
"type": "Annual"
}
]
would be easier to handle.

Iterating over a nested array in api - ReactJS

I am pulling API data as content for my ReactJS app i'm creating and i'd like to know the best method to iterate over a nested array within an array. Here's the JSON in question:
{
"code": 200,
"status": "Ok",
"copyright": "© 2015 MARVEL",
"attributionText": "Data provided by Marvel. © 2015 MARVEL",
"attributionHTML": "Data provided by Marvel. © 2015 MARVEL",
"etag": "5341faac8eb2f18f592309355057b1c40375545c",
"data": {
"offset": 0,
"limit": 20,
"total": 1,
"count": 1,
"results": [
{
"id": 1011179,
"name": "Pixie",
"description": "",
"modified": "2011-10-19T10:48:27-0400",
"thumbnail": {
"path": "http://i.annihil.us/u/prod/marvel/i/mg/8/e0/4c002f2d626ee",
"extension": "jpg"
},
"resourceURI": "http://gateway.marvel.com/v1/public/characters/1011179",
"comics": {
"available": 6,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/comics",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/39737",
"name": "Magneto: Not a Hero (2011) #1"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/24173",
"name": "Runaways (2008) #10"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/36943",
"name": "Steve Rogers: Super Soldier Annual (2010) #1"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/38083",
"name": "X-Men (2010) #19"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/41118",
"name": "X-Men (2010) #19 (Mc 50th Anniversary Variant)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/38404",
"name": "X-Men: Second Coming Revelations (Trade Paperback)"
}
],
"returned": 6
},
"series": {
"available": 5,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/series",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/14683",
"name": "Magneto: Not a Hero (2011 - 2012)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/5338",
"name": "Runaways (2008 - 2009)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/13192",
"name": "Steve Rogers: Super Soldier Annual (2010 - Present)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/9906",
"name": "X-Men (2010 - 2013)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/13832",
"name": "X-Men: Second Coming Revelations (2011 - Present)"
}
],
"returned": 5
},
"stories": {
"available": 6,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/stories",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/53571",
"name": "Interior #53571",
"type": "interiorStory"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/81928",
"name": "Steve Rogers: Super Soldier Annual (2010) #1",
"type": "interiorStory"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/90198",
"name": "Magneto: Not a Hero (2011) #1 - Int",
"type": "interiorStory"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/90479",
"name": "X-MEN: SECOND COMING REVELATIONS TPB",
"type": "cover"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/93085",
"name": "X-Men (2010) #19, Mc 50th Anniversary Variant",
"type": "cover"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/94024",
"name": "X-Men #19 Interior",
"type": "interiorStory"
}
],
"returned": 6
},
"events": {
"available": 0,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011179/events",
"items": [],
"returned": 0
},
"urls": [
{
"type": "detail",
"url": "http://marvel.com/characters/1758/pixie?utm_campaign=apiRef&utm_source=86e8919c441293aef435c128e5b5c53a"
},
{
"type": "wiki",
"url": "http://marvel.com/universe/Pixie_%28Eternal%29?utm_campaign=apiRef&utm_source=86e8919c441293aef435c128e5b5c53a"
},
{
"type": "comiclink",
"url": "http://marvel.com/comics/characters/1011179/pixie?utm_campaign=apiRef&utm_source=86e8919c441293aef435c128e5b5c53a"
}
]
}
]
}
and here's my MarvelBios.jsx file that contains the render of the data:
var React = require('react');
module.exports = React.createClass({
propTypes: {
username: React.PropTypes.string.isRequired,
bios: React.PropTypes.object.isRequired
// bios is the entireity of data from the JSON pulled in by Axios for the user inputted character name ("username")
},
render: function() {
var results = this.props.bios.data.results.map(function(result, index) {
return (
<div className="bios" key={index}>
<img src={result.thumbnail.path + "/landscape_xlarge." + result.thumbnail.extension} />
{result.name && <p>{result.name}</p>}
{result.description && <small> {result.description}</small>}
<p></p>
</div>
);
});
return (
<div>
{results}
</div>
)
}
});
I am able to successfully pull in the my first array of data from the JSON, which is results (contains character name, description and thumbnail image).
What i'd like to do is then reference the sub-array called items under that main results array, but i'm having difficulty constructing the proper code. For example I tried creating a var items = result.series.items.map(function(item, i) nested under the existing var results but that returned an undefined.
Thanks for any help.
Something like this perhaps.
module.exports = React.createClass({
propTypes: {
username: React.PropTypes.string.isRequired,
bios: React.PropTypes.object.isRequired
// bios is the entireity of data from the JSON pulled in by Axios for the user inputted character name ("username")
},
render: function() {
var results = this.props.bios.data.results.map(function(result, index) {
var items = results.comics.items.map(function(item) {
return <div>{item}</div>;
});
return (
<div className="bios" key={index}>
<img src={result.thumbnail.path + "/landscape_xlarge." + result.thumbnail.extension} />
{result.name && <p>{result.name}</p>}
{result.description && <small> {result.description}</small>}
<p>{items}</p>
</div>
);
});
return (
<div>
{results}
</div>
)
}
});

Doesn't show custom template with angularformly?

This is using angular-formly and i have created multiple-checkbox template as follows:
<script type="text/ng-template" id="multi-checkbox-template.html">
<div class="radio-group"
ng-class="{'has-error': options.formControl.$invalid}">
<label class="control-label">
{{options.label}}
{{options.required ? '*' : ''}}
</label>
<div class="radio"
ng-repeat="(key, option) in options.options">
<label>
<input type="checkbox"
formly-dynamic-name="id + '_'+ $index"
formly-custom-validation="options.validators"
id="{{id + '_'+ $index}}"
aria-describedby="{{id}}_description"
ng-value="option.value"
ng-required="options.required"
ng-model="$parent.model[$parent.options.key || $parent.index][option.name]">
{{option.name}}
</label>
<p id="{{id}}_description"
class="help-block"
ng-if="option.description">
{{option.description}}
</p>
</div>
</div>
</script>
This is config:
formlyConfigProvider.setType(
{
name: 'multi-checkbox',
templateUrl: 'multi-checkbox-template.html',
wrapper: ['bootstrapLabel', 'bootstrapHasError']
}
This is controller:
{
"key": "Q2",
"type":'multi-checkbox',
"templateOptions": {
"label": "What languages are you familiar with?",
"options": [
{ {
"name": "spanish",
"value": "spnsh"
},
{
"name": "french",
"value": "frnch"
},
{
"name": "more",
"value": "more"
}
]
}
}
];
Problem is that, doesn't show anything is the page even though error. I knew that path is correct regarding to the server response
`GET /multi-checkbox-template.html 200 1ms
This is warning i am getting,
angular-formly-bootstrap formly-field apiCheck failed! Required `label` not specified in `Argument 1/value/templateOptions`. Must be `String` https://github.com/formly-js/angular-formly/blob/6.10.0/other/ERRORS_AND_WARNINGS.md#formly-field-type-apicheck-failed
You passed:
{
"key": "Q2",
"type": "multi-checkbox",
"templateOptions": {
"to.label": "In what languages does your firm provide live chat support?",
"to.options": [
{
"name": "english",
"value": "eng"
},
{
"name": "spanish",
"value": "spnsh"
},
{
"name": "french",
"value": "frnch"
},
{
"name": "more",
"value": "more"
}
]
},
"$$hashKey": "object:592",
"data": {},
"validation": {
"messages": {}
},
"id": "formly_1_multi-checkbox_Q2_5"
}
With the types:
{
"key": "string",
"type": "string",
"templateOptions": {
"to.label": "string",
"to.options": {
"0": {
"name": "string",
"value": "string"
},
"1": {
"name": "string",
"value": "string"
},
"2": {
"name": "string",
"value": "string"
},
"3": {
"name": "string",
"value": "string"
}
}
},
"$$hashKey": "string",
"data": "Object",
"validation": {
"messages": "Object"
},
"value": "Function",
"runExpressions": "Function",
"resetModel": "Function",
"updateInitialValue": "Function",
"id": "string",
"initialValue": "undefined"
}
The API calls for:
{
"__apiCheckData": {
"strict": false,
"optional": false,
"type": "shape"
},
"shape": {
"templateOptions": {
"__apiCheckData": {
"strict": false,
"optional": false,
"type": "shape",
"error": "THIS IS THE PROBLEM: Required `label` not specified in `templateOptions`. Must be `String`"
},
"shape": {
"label": "String <-- YOU ARE MISSING THIS"
}
}
}
}
`
Please if there is any help i will be really thank you.
I think some of your references to options above should be referring to options.templateOptions instead (you can actually refer to this as to as a shortcut). For instance, options.label and options.options should be to.label and to.options. Not sure if this is the only issue though.
Also, the script tag business seems weird to me, but I always use:
template: require('path-to-my-template') and Webpack, so I can't be sure.
templateUrl in your formlyConfigProvider.setType() is not a directory link to your file.
the templateUrl is actually referring to the id attribute in your script tag
what you should do is:
formlyConfigProvider.setType(
{
name: 'multi-checkbox',
templateUrl: 'custom-template.html'
wrapper: ['bootstrapLabel', 'bootstrapHasError']
}
and in your template html file:
<script type="text/ng-template" id="custom-template.html">
<!-- your custom template should be here -->
</script>

Resources