根据需要加载角度textngngular

时间:2015-09-04 21:50:59

标签: angularjs

我正在尝试按需设置textAngular,即何时以及是否需要它。 textAngular应用程序可以工作,如果我在文件中有以下html ..

<body>
<div ng-app="textAngularTest" ng-controller="wysiwygeditor" class="container app">
<div text-angular="text-angular" name="htmlcontent" ng-model="htmlcontent" ta-disabled='disabled'></div> 
</div>
</body>

和js功能

  angular.module("textAngularTest", ['textAngular']).controller('wysiwygeditor', function wysiwygeditor($scope) {
      $scope.orightml = '<h2>Try me!</h2>';
      $scope.htmlcontent = $scope.orightml;
      $scope.disabled = false;
  });

要尝试这个,我将从html中删除ng-app指令并包装在一个函数中并使用bootstrap启动...

 function apply(){

      var app= angular.module("textAngularTest", ['textAngular']);

      app.controller('wysiwygeditor', function wysiwygeditor($scope) {
      $scope.orightml = '<h2>Try me!</h2>';
      $scope.htmlcontent = $scope.orightml;
      $scope.disabled = false;
        });

      angular.bootstrap(document, ["textAngularTest"]);
  }

不幸的是,这不起作用,对此有何建议?

Codepen http://codepen.io/ambrosedheffernan/pen/vNEapL

1 个答案:

答案 0 :(得分:1)

条件自举可能不是最优雅的解决方案,但在非SPA情况下它可能有效。是的,它可以正常工作

http://codepen.io/anon/pen/dYPqYO

删除ng-app

angular.bootstrap(document, ["textAngularTest"]);

加入。

相关问题