Skip to content

Instantly share code, notes, and snippets.

@Hyra
Created June 8, 2014 13:03
Show Gist options
  • Save Hyra/0cc9cf03ed9a4c366aa3 to your computer and use it in GitHub Desktop.
Save Hyra/0cc9cf03ed9a4c366aa3 to your computer and use it in GitHub Desktop.
// 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