首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按需加载角textAngular

按需加载角textAngular
EN

Stack Overflow用户
提问于 2015-09-04 21:50:58
回答 1查看 224关注 0票数 0

我正在尝试按需设置textAngular,即何时和如果我需要它。如果文件中有下面的html,textAngular应用程序就能工作。

代码语言:javascript
复制
<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函数

代码语言:javascript
复制
  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指令,并将其封装在函数中,并使用引导程序来启动.

代码语言:javascript
复制
 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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-04 23:55:12

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

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

删除ng-app

代码语言:javascript
复制
angular.bootstrap(document, ["textAngularTest"]);

已添加。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32407065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档