Created
June 8, 2014 13:03
-
-
Save Hyra/0cc9cf03ed9a4c366aa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TestController.js | |
module.exports = function (app) { | |
return function($scope) { | |
$scope.somevar = 'Whatever'; | |
}; | |
}; | |
// App.js | |
var angular = require('angular'); | |
var uiRouter = require('ui-router'); | |
var app = angular.module('testApp', [uiRouter]); | |
app.config(function($stateProvider) { | |
$stateProvider | |
.state('home', { | |
url: "/", | |
controller: 'TestController', | |
templateUrl: "templates/home.html" | |
}) | |
}) | |
.controller('TestController', require('TestController')(app)); | |
// This works, but ideally you want to do it like this. Which doesn't work as it can't match the name of the controller .. | |
// App.js | |
var angular = require('angular'); | |
var uiRouter = require('ui-router'); | |
var app = angular.module('testApp', [uiRouter]); | |
app.config(function($stateProvider) { | |
$stateProvider | |
.state('home', { | |
url: "/", | |
controller: require('TestController')(app), | |
templateUrl: "templates/home.html" | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment