angular-material-npfixed
Version:
The Angular Material project is an implementation of Material Design in Angular.js. This project provides a set of reusable, well-tested, and accessible Material Design UI components. Angular Material is supported internally at Google by the Angular.js, M
46 lines (43 loc) • 1.4 kB
JavaScript
/**
* ngPanel by @matsko
* https://github.com/matsko/ng-panel
*/
angular.module('docsApp')
.directive('ngPanel', ['$animate', function($animate) {
return {
restrict: 'EA',
transclude: 'element',
terminal: true,
compile: function(elm, attrs) {
var attrExp = attrs.ngPanel || attrs['for'];
var regex = /^(\S+)(?:\s+track by (.+?))?$/;
var match = regex.exec(attrExp);
var watchCollection = true;
var objExp = match[1];
var trackExp = match[2];
if (trackExp) {
watchCollection = false;
} else {
trackExp = match[1];
}
return function(scope, $element, attrs, ctrl, $transclude) {
var previousElement, previousScope;
scope[watchCollection ? '$watchCollection' : '$watch'](trackExp, function(value) {
if (previousElement) {
$animate.leave(previousElement);
}
if (previousScope) {
previousScope.$destroy();
previousScope = null;
}
var record = watchCollection ? value : scope.$eval(objExp);
previousScope = scope.$new();
$transclude(previousScope, function(element) {
previousElement = element;
$animate.enter(element, null, $element);
});
});
};
}
};
}]);