Javascript Angular has a peculiar pattern for creating controllers that looks like this:
myApp.controller('myController', ['$scope', 'foo', 'bar',
function($scope, foo, bar) {
//do stuff...
}]);
The '$scope', 'foo', 'bar'
thing is repeated as the parameter list in the function inside the square-bracketed array.
I thought I could make doing this less error-prone by writing a yasnippet. It looks like this:
# -*- mode: snippet -*-
# name: angctl
# key: angctl
# --
$1.controller('$2', ['$3', function($3) {
$0;
}]);
This works fine, but only if there is one parameter (in the $3 position), like if I'm just using $scope
. If I want to use more than one, it breaks down.
Is there some way of writing the snippet so it will make a comma delimited list of quoted strings and repeat a comma delimited list of unquoted strings somewhere else within the snippet?