Ich bin auf der Suche nach der besten Praxis für eckige 1-Komponente und CMS-Ansatz.AngularJS Best Practice für Komponente und cms App
Ich plane, mehrere Etikettenvorlagen zu erstellen, und ich möchte, dass dieses Projekt komponentengesteuert, hoch wiederverwendbar und von einem CMS-Inhalt gesteuert wird. mit kompilieren $ Dienst wie diese
Ich plane JSON als Baum von Komponenten zu verwenden und nur den Baum Schritt für Schritt kompilieren:
angular.module('app.compile', [], function($compileProvider) {
$compileProvider.directive('compile', function($compile) {
return function(scope, element, attrs) {
scope.$watch(
function(scope) {
// watch the 'compile' expression for changes
return scope.$eval(attrs.compile);
},
function(value) {
// when the 'compile' expression changes
// assign it into the current DOM
element.html(value);
// compile the new DOM and link it to the current
// scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
}
);
};
});
});
http://plnkr.co/edit/MwUjE9l6U5wMkE89kwqY?p=preview
- Ich würde gerne wissen, ob hat jemand das schon mal probiert und kann sein Feedback teilen?
- Klingt es nach einer guten Lösung? Ist dies die beste verfügbare Praxis?
- Wird diese Methode für die Verwendung von
$compile
Service möglicherweise schlecht für die Leistung sein?