Skip to content

Instantly share code, notes, and snippets.

@cognitom
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognitom/d07d231b28d2e9e7bd10 to your computer and use it in GitHub Desktop.
Save cognitom/d07d231b28d2e9e7bd10 to your computer and use it in GitHub Desktop.
CommonJSフレンドリーな、Angularアノテーション ref: http://qiita.com/cognitom/items/c7b4ffcd26f87b66af8a
// インジェクション方法 A
$injector.invoke(function(serviceA){});
// インジェクション方法 B
$injector.invoke(['serviceA', function(serviceA){}]);
// app.js
angular.module('app', [])
.controller('mainCtrl', require('./mainCtrl'));
// mainCtrl.js
module.exports = [
'$scope', '$location', '$filter',
function ($scope, $location, $filter) {
// some angular code
}
]
// @ngInject
module.exports = function ($scope, $location, $filter) {
// some angular code
}
gulp = require 'gulp'
browserify = require 'browserify'
ngannotate = require 'browserify-ngannotate'
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'
streamify = require 'gulp-streamify'
uglify = require 'gulp-uglify'
sourcemaps = require 'gulp-sourcemaps'
path = require 'path'
$ =
src: './src/ng/app.js'
dist: './public/js/'
gulp.task 'browserify', ->
browserify
entries: [$.src]
.transform ngannotate
.bundle()
.pipe source path.basename $.src
.pipe buffer()
.pipe sourcemaps.init loadMaps: true
.pipe streamify uglify()
.pipe sourcemaps.write './'
.pipe gulp.dest $.dist
// app.js
angular.module('app', [])
.controller('mainCtrl', require('./mainCtrl'));
// mainCtrl.js
var inject = require('ng-injector');
inject('$scope');
inject('$location');
inject('$filter');
module.exports = inject(function ($scope, $location, $filter) {
// some angular code
});
// mainCtrl.js
var inject = require('ng-injector');
module.exports = inject(
['$scope', '$location', '$filter'],
function ($scope, $location, $filter) {
// some angular code
});
// mainCtrl.js
var inject = require('ng-injector');
inject('$scope');
inject('$location');
inject('$filter');
module.exports = inject(function ($scope, $location, $filter) {
// some angular code
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment