Skip to content

Instantly share code, notes, and snippets.

@sanusart
Created June 26, 2014 16:20
Show Gist options
  • Save sanusart/ddb054ad79d91ba5b068 to your computer and use it in GitHub Desktop.
Save sanusart/ddb054ad79d91ba5b068 to your computer and use it in GitHub Desktop.
AngularJS base snippets #Angular
// Routing
angular.module('myAppName', [])
.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/home.html',
controller: 'homeCtrl'
})
.when('/inner', {
templateUrl: 'views/inner.html',
controller: 'innerCtrl'
})
.otherwise({
redirectTo: '/'
});
});
//Conteroller
angular.module('myAppName', [])
.controller('controllerNameCtrl', function($scope) {
// Conroller stuff here
});
// directive
angular.module('myAppName', [])
.directive('directiveName', function (injectables) {
return {
restrict: 'A', // A,E,M,C or even AE
template: '<div></div>',
templateUrl: 'directive.html', // If present
replace: false,
priority: 0,
transclude: false,
scope: false,
terminal: false,
require: false,
controller: function($scope, $element, $attrs, $transclude, otherInjectables) {
// Controller if used
},
compile: function compile(tElement, tAttrs, transclude) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
// pre-link function()
},
post: function postLink(scope, iElement, iAttrs, controller) {
// post-link function() - executed by link()
}
};
},
link: function postLink(scope, iElement, iAttrs) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
// pre-link function()
},
post: function postLink(scope, iElement, iAttrs, controller) {
// post-link function() - executed by link()
}
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment