Here's the code snippet for a tiny Angular application I'm working on:
var myApp = angular.module("MyApp", []);
myApp.factory("Items", function()
{
var items = {};
items.query = function()
{
return
[
{
title: "Mary had a little lamb",
price: 2.5,
},
{
title: "My Experiments with Truth",
price: 6.25,
},
{
title: "Indian Summer",
price: 5.75,
},
];
};
return items;
});
function ItemsViewCtrl($scope, Items)
{
$scope.items = Items.query();
$scope.numberOfItems = function()
{
window.alert("We have "+$scope.items.length+" with us");
};
}
I've set up a module, a service, and a controller, but there seems to be an issue. The items array is not accessible in the template when using the ng-controller directive.
I even tried creating the controller using module.controller() without success. What am I missing here?