javascript - how to inject controller in routeprovider -


i quite new angularjs, here suggested problem.

i have route.js file stores route related stuff. looks this.

var app = angular.module('ontology', ['ngroute']);  app.config(['$routeprovider', function ($routeprovider) {     $routeprovider         .when('/abduction', {             templateurl: '/partials/abduction.html',             controller: 'axiomformctrl',         })         .when('/logicdifference', {             templateurl: '/partials/logicdifference.html',             controller: 'axiomformctrl',         })     .otherwise({ redirectto: '/' }); }]); 

and have file ontology.js has controller , 1 of controller axiomformctrl.

var app = angular.module('ontology', ['ngresource', 'ngroute']);  app.controller('axiomformctrl', function ($scope, $http) {     console.log("in axiom form ctrl...."); }); 

now if ran program, axiomformctrl undefined. not sure how can resolve dependency problem.

first, make sure including script ontology.js in html:

... <script src="routes.js"></script> <script src="ontology.js"></script> 

second, defining module twice, here:

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

and here:

var app = angular.module('ontology', ['ngresource', 'ngroute']); 

so, define 1 time, of required modules. might done in file called app.js (which you'll need include in html):

app.js

(function() {     var app = angular.module('ontology', ['ngresource', 'ngroute']); })(); 

and in of other files use ontology model, use same syntax, minus second parameter (the array of other modules):

routes.js

(function() {     var app = angular.module('ontology');      app.config(['$routeprovider', function ($routeprovider) {         $routeprovider             .when('/abduction', {                 templateurl: '/partials/abduction.html',                 controller: 'axiomformctrl',             })             .when('/logicdifference', {                 templateurl: '/partials/logicdifference.html',                 controller: 'axiomformctrl',             })         .otherwise({ redirectto: '/' });     }]); })(); 

and ontology.js

(function () {     var app = angular.module('ontology');      app.controller('axiomformctrl', function ($scope, $http) {         console.log("in axiom form ctrl....");     }); })(); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -