I'm trying to display an object of an object in an array, I've been hitting my head against the wall since I cant change the backend.
this is what I got so far, M01, M02, M03... might refer to months since we are November there are 11 however if it was February id be only M01 and M02. since I got a property of an object I cant loop it on a second for and I'm having a lot of trouble with it
this is my view
<div *ngIf="estados" class="table-responsive col-lg-12 tablilla">
<table class="table table-bordered table-striped table-responsive">
<thead>
<tr>
<th></th>
<th *ngFor="let month of listaMonthsNames">{{month}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let estado of estados">
<td>{{estado.nom_item}}</td>
<td *ngFor="let month of estado.M[0]">{{month}}</td>
</tr>
</tbody>
</table>
</div>
I think this will help you :
There is no direct way to access Object from the Template side so,
All you need to do is provide Object.keys access to the Template side by this way from Component :
// Component Side :
objectKeys = Object.keys;
// Template Side :
<td *ngFor="let key of objectKeys(estado.M)">
Key: {{key}}, value: {{estado.M[key]}}
</td>
You can read more about the Object.keys HERE
I have a small problem I would like to set up a ng-repeat dynamic with the values I receive from my JSON object,
First, i made my th from my table with the keys
Secondly, i would like to do my td in dynamic (without putting the name of the key ex: obj.NOM, obj.TYPE ...)
I managed to do something with an Object.keys but logic is not good so I need some help
this is my JSON object ( i show you just the little piece of code that I have a problem )
"HEADER":[
{"NOM":"API-APP","TYPE":"string","DESCRIPTION":"Code application"},
{"NOM":"API-SIGNATURE","TYPE":"string","DESCRIPTION":"Signature de la requete API"},
{"NOM":"API-TIMESTAMP","TYPE":"integer","DESCRIPTION":"Timestamp en microseconde"}]
and this is my ng repeat
<span><b>HEADER</b></span>
<br>
<br>
<table class="table">
<th ng-repeat ="(key, itemHeader) in itemHead.HEADER[0] track by $index">{{key}}</th>
<tr ng-repeat ="(key, itemHeader) in itemHead.HEADER track by $index" >
<td>{{getFirstPropertyValue(itemHeader,$index)}}</td>
</tr>
</table>
I explain i made first a ng-repeat for th with the keys and I would like put my data (3 data per row) in td without put ( .NOM .TYPE .DESCRIPTION)
So I took the function object.key which works very well but that makes me just one element per row but I need 3 elements per row
this is my scope for the function object.key
$scope.getFirstPropertyValue = function(obj,index){
return obj[Object.keys(obj)[index]];
}
and this my result
thanks in advance for your help
<table class="table">
<thead>
<tr>
<th ng-repeat="(key, itemHeader) in itemHead.HEADER[0]">
{{key}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in itemHead.HEADER">
<td ng-repeat="column in row">
{{column}}
</td>
</tr>
</tbody>
</table>
I am trying to redirect the page using ng-click which is avail in ng-repeat.
ng-repeat code:
<tr ng-repeat="students in studlist" ng-click="gotoProfile(1)">
<td width="12%" class="student-list-pic-column"><img src="<?=base_url()."data/student-img/{{ students.photo }}";?>"></td>
<td width="50%" class="custom-table-border-body text-left">{{ students.studname }}</td>
<td width="38%">{{ students.bid }}</td>
</tr>
<tr ng-show="!studlist.length">
<td colspan="3" class="custom-table-border-body text-center">
Search student name ...
</td>
</tr>
Here in ng-click="gotoProfile(1)" instead of that 1 I need {{students.id}} but unable to get
Controller function:
$scope.gotoProfile = function (sid) {
console.log($scope.purl);
var rurl = $scope.purl+sid;
$location.url(rurl);
};
When I run this I am getting url
http://localhost/product/tcm_dev/utility/dashboard#/http://localhost/product/tcm_dev/utility/student/profile/1
like this.
Please help.
Thank You
Prashant
use <tr ng-repeat="students in studlist" ng-click="gotoProfile(student.id)"> to send student.id
and how about use $window.location.href=(rurl); instead of $location.url(rurl);
if you want to open a new page, use $window.location.href=(rurl,'_blank');
I have a json file in the root of my angularjs application. I’m able to view this data in one of my webpages which is perfect, but I would like to expand on this and be able to make each name showing up linkable to a separate page where other more detailed information comes up based on the ID or record chosen.
My questions are,
1.) Is it possible to accomplish what I’m asking without using a database? If it’s not possible, can you point me to a resource that shows how this is done using Laravel and Angular?
2.) If this is possible to do this with just Angular can you please show me an example on how to do this?
//team.html
<div class="whitecontainer">
<div>
<h1>Aguiluchos Team Roster</h1><input type="text" data-ng-model="searchTeam">
<div ng-app="myApp" ng-controller="AguiluchosCtrl">
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>
Name
</td>
<td>
Position
</td>
<td>
Number
</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in Names | filter:searchTeam">
<td>{{ x.Name }}</td>
<td>{{ x.Position }}</td>
<td>{{ x.Number }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
/app.js
latestAguiluchosApp.controller('AguiluchosCtrl', function($scope, $http) {
$http.get("scripts/aguiluchos.json")
.success(function(response) {$scope.Names = response.records;});
});
/aguiluchos.json
{
"records":
[
{"Name":"Alejandro, Barajas","Position":"GK","Number":29},
{"Name":"Devin, Collins","Position":"M","Number":12},
{"Name":"Derek, Drodrill","Position":"D","Number":3},
{"Name":"Devante, Dubose","Position":"D","Number":18},
{"Name":"Matheus, Freire","Position":"M","Number":16},
{"Name":"Jesus, Gomez","Position":"GK","Number":20},
{"Name":"Kevin, Gonzalez","Position":"GK","Number":"NA"},
{"Name":"Ricardo, Guerra","Position":"M","Number":24},
{"Name":"Allan, Gutierrez","Position":"D","Number":4},
{"Name":"Hany, Helmy","Position":"M","Number":7},
{"Name":"Alejandro, Jauregui","Position":"M","Number":17},
{"Name":"Jesus, Leon","Position":"D","Number":21},
{"Name":"Julio, Lopez","Position":"M","Number":19},
{"Name":"Jose, Majano","Position":"GK","Number":1},
{"Name":"Adan, Martinez","Position":"D","Number":8},
{"Name":"Benjamin, Middlemiss","Position":"M","Number":13},
{"Name":"Ross, MIddlemiss","Position":"F","Number":2},
{"Name":"Michael, Molinari","Position":"M","Number":6},
{"Name":"Juan, Mondragon","Position":"D","Number":26},
{"Name":"Jesus, Morales","Position":"M","Number":11},
{"Name":"Leopoldo, Morales","Position":"M","Number":"NA"},
{"Name":"Greivin, Pacheco","Position":"F","Number":9},
{"Name":"Jose, Prieto","Position":"D","Number":23},
{"Name":"Noel, Prieto","Position":"F","Number":"NA"},
{"Name":"Flavio, Ramos","Position":"M","Number":"NA"},
{"Name":"Simon, Rawnsley","Position":"F","Number":5},
{"Name":"Miguel, Santiago","Position":"M","Number":22},
{"Name":"Drew, Scafani","Position":"D","Number":14},
{"Name":"Alejandro, Sorto","Position":"F","Number":15},
{"Name":"Ryan, Trutner","Position":"M","Number":"NA"}
]
}
Thank you,
Sincerely,
Jesus
In this example I have a main.html template
<!DOCTYPE html>
<html>
<head>
<title>Backend</title>
<style>
html, body {height:100%}
</style>
</head>
<body>
<table border="1" width="100%" height="100%">
<tr>
<td colspan="2" class="td-header">
<h1>Google GO</h1>
</td>
</tr>
<tr>
<td class="td-right-content">
{{<parsed template from children>}}
</td>
</tr>
<tr>
<td colspan="2" class="td-header">
<h1>Footer</h1>
</td>
</tr>
</table>
</body>
</html>
The child part would fill the
{{}}
With
<table>
<tr>
<th>
Name
</th>
<th>
Description
</th>
<th>
</th>
</tr>
{{range .}}
<tr>
<td>
{{.Name}}
</td>
<td>
{{.Description}}
</td>
<td>
Edit
</td>
</tr>
{{end}}
</table>
After it has been parsed in the code of child part.
I am doing this to eliminate redundant html and css and to manage the design easily.
Thanks all!
A Template object contains a top-level template (here: the parent template) which may reference other templates associated in the same object. Templates have a name used for referencement.
It can be tricky, because when you use the ParseFiles function to create a new object, each template is named using the base name of the file (and it seems to be impossible to change that name). If you have multiple possible children files for a given main, it can be impractical because you usually don't want to give them the same name.
The solution it to manually read the file to a string and then add it to an explicitly named template (a little bit cumbersome IMO, but you can live with it).
main_temp,_ := template.ParseFiles("main.html")
cont_s,_ := ioutil.ReadFile("content1.html")
// add a new associated template to main
cont_temp,_ := main_temp.New("content").Parse(string(cont_s))
g := Content{"Hi"}
main_temp.Execute(os.Stdout, &g)
(I skipped all the error handling for the example)
Then you can use the {{template}} directive in your parent page:
{{template "content" .}}
(or any pipeline instead of . which is referring to the whole object given to main_temp)
See text/template doc for more details