Javascript AngularJS组件和cms驱动应用程序的最佳实践
我正在寻找角1组件和CMS驱动方法的最佳实践 我计划建立多个标签模板,我希望这个项目是组件驱动的,高度可重用的,由CMS内容驱动 我计划使用JSON作为组件树,并使用$compile服务一步一步地编译该树,如下所示:Javascript AngularJS组件和cms驱动应用程序的最佳实践,javascript,angularjs,performance,compilation,components,Javascript,Angularjs,Performance,Compilation,Components,我正在寻找角1组件和CMS驱动方法的最佳实践 我计划建立多个标签模板,我希望这个项目是组件驱动的,高度可重用的,由CMS内容驱动 我计划使用JSON作为组件树,并使用$compile服务一步一步地编译该树,如下所示: angular.module('app.compile', [], function($compileProvider) { $compileProvider.directive('compile', function($compile) { return function
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);
}
);
};
});
});
$compile
服务的这种方法会对性能有害吗我更喜欢使用角度分量。我使用$compile只是为了动态使用我的组件。仅使用指令来更改DOM。如果控件具有模板,请改用组件 检查一下那个样品 Tks