I'm learning basics of Angular and have a problem with getting data form simple rest api. I read this: How to write an angularJs Controller to GET Rest Data from Parse.com
And still don't know what is wrong in this code: Controller:
Todoapp.controller('DaneAPI' ['$scope', '$http', function($scope, $http) {
$scope.items = [];
$scope.getItems = function() {
$http({
method : 'GET',
url : '/todos'
}).then(function(data, status) {
$scope.items = data;
}, function(data, status) {
alert("Error");
}
);
}}]);
And in html (to be more precise its .ejs cause I'm using express, but that shouldn't matter):
<body ng-controller="TodosCtrl as todos">
<ul clas="nav nav-pills">
<li> <a href ng-click="tab = 'daneZapi'">DaneZApi</a></li>
</ul>
<div class="panel" ng-show="tab === 'daneZapi'" ng-controller="DaneAPI">
<button type="button" ng-click="getItems()">Get Items</button>
<ul>
<li ng-repeat="item in items.name">
{{item.name}}
</li>
</ul>
</div>
</body>
GET send to localhost:3000/todos works ok - I testes it with Postman and it's giving me some data.
And one more question that I can't figure out - why does ng-show does not work for <button>
? It's visible despite what is in "tab". In full listing I have 3 tabs.