Unknow Provider with AngularJS -
i trying request jason file angularjs.i using yeoman. these 3 files.
in view folder:main.html
<div class="jumbotron"> choose category1 <div class="wrap" ng-controller="mainctrl"> <select ng-model="selectedvalue" ng-change="loaddata()" > <option value="1">category 1</option> <option value="2">category 2</option> <option value="3">category 3</option> <option value="4">category 4</option> <option value="5">category 5</option> </select> <div ng-show="selectedvalue != null" class="main"> <center><h2>results category {{ selectedvalue }}</h2></center> <br><br> </div> <div class="main" > <ul class="cloudlist"> <li class="service" ng-repeat="item in services" ng-click="select(item)"> <div class="info"> <h3>{{item.service_name}}</h3> <b>{{item.status_page}}</b><br> <b>is billed : {{item.is_billed.billing_term._identifier}}</b> </div> </li> </ul> <br> </div> </div>
in controllers folder: main.js
'use strict'; angular.module('frontendapp') .controller('mainctrl', ['$scope', '$http','services', function ($scope, $http, services) { $scope.loaddata = function () { $scope.services = services.query(); }; $scope.select = function (item) { // item here when service clicked }; }]);
in services folder: services.js
'use strict'; angular.module('frontendapp').factory('services', function($resource) { return $resource('/services/:serviceid', { serviceid: '@_id' }, {}); });
i error
error: [$injector:unpr] unknown provider: servicesprovider <- services <- mainctrl http://errors.angularjs.org/1.3.15/$injector/unpr?p0=servicesprovider%20%3c-%20services%20%3c-%20mainctrl minerr/<@http://localhost:9000
solution: using yeoman , forgot execute command yo angular:service services
try code in main.js
var module = angular.module('frontendapp', ['ngresource']); module.factory('myservices', ['$resource', function($resource) { return $resource('/services/:serviceid', { serviceid: '@_id' }, {}); }]); module.controller('mainctrl', ['$scope', '$http','myservices', function ($scope, $http, myservices) { $scope.loaddata = function () { $scope.services = myservices.query(); }; }]);
Comments
Post a Comment