Vote count:
0
It seems that my html file isn't calling the controller's method. I tried using "ng-controller="ProviderListCtrl"", but it doesn't work anyway. The tag ngRepeat doesn't recognize the "Providers" and it doesn't iterate. I tried to use app.js with configuration to link the controller to my html file, but it doesn't work too.
What am I doing wrong? :/
Module and Resource objects (services.js)
var services = angular.module('ngdemo.services', ['ngResource']);
services.factory('ProvidersFactory', function ($resource) {
return $resource('http://ift.tt/1tLsnQr', {}, {
query: { method: 'GET', isArray: true },
})
});
Controller (controller.js)
var app = angular.module('ngdemo.controllers', []);
app.controller('ProviderListCtrl', ['$scope', 'ProvidersFactory', '$location',
function ($scope, ProvidersFactory, $location) {
$scope.providers = ProvidersFactory.query();
}]);
app.js
angular.module('ngdemo', ['ngdemo.filters', 'ngdemo.services', 'ngdemo.directives', 'ngdemo.controllers']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/provider-list', { templateUrl: '/provider-list.html', controller: 'ProviderListCtrl' });
$routeProvider.otherwise({ redirectTo: '/provider-list' });
}]);
HTML
<!DOCTYPE html>
<html ng-app xmlns="http://ift.tt/lH0Osb">
<head>
<title>Providers</title>
<link href="Content/bootstrap.min.css" rel="stylesheet">
<script src="Scripts/Vendor/angular.min.js"></script>
<script src="Scripts/Vendor/angular-resource.js"></script>
<script src="controller.js"></script>
<script src="services.js"></script>
<script src="app.js"></script>
</head>
<body role="document" style="padding-top: 70px; padding-bottom: 30px">
<div class="container body-content" role="main">
<div ng-controller="ProviderListCtrl">
<h2>Providers</h2>
<hr>
<div style="width:60%">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th style="min-width: 30px; width: 30px;">Id</th>
<th style="min-width: 100px;">Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="provider in providers">
<td valign="middle">Test: {{provider.Id}}</td>
<td valign="middle">Test: {{provider.Name}}</tdvalign>
<td valign="middle" align="right" width="40px"><a ng-click="" class="btn btn-small btn-primary">edit</a></td>
<td valign="middle" align="right" width="50px"><a ng-click="" class="btn btn-small btn-danger">delete</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
asked 28 secs ago
Aucun commentaire:
Enregistrer un commentaire