i have thee angular service , 1 controller. , i'm including files this;
<script type="text/javascript" src="view/product/productservice.js"></script> <script type="text/javascript" src="view/invoice/invoiceservice.js"></script> <script type="text/javascript" src="view/invoice/invoicecontroller.js"></script>
in order i'm getting error: [$injector:unpr] http://errors.angularjs.org/1.4.8/$injector/unpr?p0=productprovider%20%3c-%20product%20%3c-%20invoicecontroller
but when change order shown below, every thing ok.
<script type="text/javascript" src="view/invoice/invoiceservice.js"></script> <script type="text/javascript" src="view/product/productservice.js"></script> <script type="text/javascript" src="view/invoice/invoicecontroller.js"></script>
there no dependency in service files, error occurs depens on javascript files order. here files content
productservice.js
angular.module('mainapp.services',[]).service('product',function($resource){ return $resource('http://localhost/invocy/api/public/product/:id', { id: '@id' }, { update: { method: 'put' } }); });
invoiceservice.js
angular.module('mainapp.services',[]).service('invoice',function($resource){ return $resource('http://localhost/invocy/api/public/invoice/:id', { id: '@id' }, { update: { method: 'put' } }); });
invoicecontroller.js
angular.module('mainapp.controllers', []).controller('invoicecontroller', function($scope,product) { $scope.invoiceproducts = []; $scope.sub_total=0; $scope.tax_total=0; $scope.addproduct = function() { $scope.invoiceproducts.push( { name:'xxx', quantity:1, unit_price:0, total:0 } ); }; $scope.addproduct(); $scope.updatetotals=function(){ angular.foreach(invoiceproducts,function(key,invoiceproduct){ $scope.sub_total+=invoiceproduct.total; $scope.tax_total=100; }); $scope.general_total=$scope.sub_total+$scope.tax_total; }; /* Ürün arama */ $scope.products=new product(); $scope.selectednumber = null; // instantiate bloodhound suggestion engine var numbers = new bloodhound({ datumtokenizer: function(d) { return bloodhound.tokenizers.whitespace(d.num); }, querytokenizer: bloodhound.tokenizers.whitespace, local: $scope.products.$query() }); // initialize bloodhound suggestion engine numbers.initialize(); $scope.numbersdataset = { displaykey: 'num', source: numbers.ttadapter() }; });
angular.module('mainapp.services',[])
this defines module named 'mainapp.services'. if such module has been defined before, overwrites completely. should not use in service files. reference defined module, syntax is
angular.module('mainapp.services')
without array of dependencies second argument.
declare modules in separate file, included first, add services , controllers these modules.
Comments
Post a Comment