小编Bna*_*Zil的帖子

AngularJS组件和cms驱动应用程序的最佳实践

我正在寻找角度1组件和CMS驱动方法的最佳实践.

我打算构建多个标签模板,我希望这个项目是由组件驱动的,高度可重用的,并由CMS内容驱动.

我打算使用JSON作为组件树,并使用$ compile服务一步一步地编译树,如下所示:

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);
            }
        );
    };
  }); …
Run Code Online (Sandbox Code Playgroud)

javascript performance components compilation angularjs

5
推荐指数
1
解决办法
332
查看次数