unfoudev unfoudev - 8 months ago 35
AngularJS Question

Print array elements AngularJS

I would print a string with Angular variables.

var app = angular.module('monApp',[]);
"prenom": "Jean",
"nom": "Dupont",
"dateNaissance": new Date(1991,11,1)


I would like to print Hello Jean Dupont born on "1991-11-30T23:00:00.000"
I have tried many ways to print finded on web but no result.

<body data-ng-app="monApp" class ="ng-scope">
<div data-ng-controller="Controleur" class ="ng-scope" ><p>Hello {{prenom}} {{scope.infos[1], born on {{scope.infos[2]}}</p></div>



$scope.infos is a Object not Array, you should select to it with $scope.infos['propertyName'] or $scope.infos.propertyName


<div ng-app="app">
  <div ng-controller="Controller">
    <p>Hello {{infos.prenom + ' ' + infos.nom + ', born on ' + infos.dateNaissance}}</p>


var app = angular.module('app', []);
app.controller('Controller', function($scope) {
  $scope.infos = {
    "prenom": "Jean",
    "nom": "Dupont",
    "dateNaissance": new Date(1991,11,1)

See example: Here