javascript - Undefined service controller using route -


i using angular service route service file separate. , face branchservice undefined error in console.see code in plunker code here branchservice.js:

 angular.module("myapp").service('branchservice', ['$http', function ($http) {     var link = "http://localhost:8008/";     //----get dining tables`enter code here`     this.getbranches = function ($scope) {         return $http({             method: "get",             url: encodeuri(link + "branch/getbranches/"),             headers: { 'content-type': 'application/json' }         }).success(function (data) {             console.log(data);         }).error(function (data) {             console.log(data);         });     }; }]); 

and mycontroller.js here:

var app = angular.module("myapp", ['ngroute']);  app.config(function ($routeprovider) {     $routeprovider         .when('/branches', {             templateurl: 'branches.html',             controller: 'branchcontroller'         })          .otherwise({             redirectto: '/branches'         }); });  app.controller('branchcontroller', ['$scope', '$filter', 'branchservice', function ($scope, $filter, branchservice) {    branchservice.getbranches($scope); } 

when run error: $injector:modulerr module error error show in console

before using service inject first can use it

var app = angular.module("myapp", ['ngroute', 'branchservice']); 

edit :

this problem in branchcontroller.js:

var app = angular.module("myapp", ['ngroute']); 

you injected ngroute again in fact added in app.js :

var app = angular.module("myapp",['ngroute']);

to fix : remove ng route

var app = angular.module("myapp"); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -