I am having trouble declaring 2 controllers in 1 app. My guess is it's a syntax error, but not totally sure.
The error message I receive is that "people is not defined".
//this is my app file
var myApp = angular.module('myApp',[]);
myApp.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
myApp.controller('controller1', function($scope) {
var pets = [
{animal: "dog", years: "3 Years"},
{animal: "dog", years: "1 Years"},
];});
myApp.controller('controller2', function($scope) {
var people = [
{name: "john", bday: "september"},
{name: "nancy",bday: "december"},
];
});
On my html page, I am simply writing some javascript that attempts to get the length of the people array.
var totalpeople = people.length;
Note: Not sure if this is important information, but I declare my app in the html tag.
update: here some some basic pseudo code on my html page.
<html ng-app="myApp">
<head>
<script>
var totalpeople = people.length;
</script>
</head>
<body>
<div ng-controler="controller1">
<table><tr ng-repeat="rows in pets">
<td>{[{pets.animal}]}</td><td>{[{pets.year}]}</td>
</tr>
</div>
<div ng-controler="controller2">
<table><tr ng-repeat="rows in people">
<td>{[{pets.name}]}</td><td>{[{pets.bday}]}</td>
</tr>
</div>
<div>
<table><tr>
<td><script>//not actually doing this, but totalpeople goes here </script></td>
</tr>
</div>
</body>
people.peopleorpetsin your controllers. You would want to declare them asthis.peopleandthis.petsrespectively.