【问题标题】:How come Ace editor won't work correctly in my Meteor/Angular application?为什么 Ace 编辑器无法在我的 Meteor/Angular 应用程序中正常工作?
【发布时间】:2013-09-03 21:14:12
【问题描述】:

我创建了一个example Meteor application,它与AngularJS 集成,并通过UI.Ace Angular 指令嵌入了Ace editor。然而,虽然编辑器出现了,但它不接受输入。在 Chromium/Chrome 中,只有在我打开或关闭开发者工具之后,编辑器才会做出反应并对输入做出响应(编辑器必须对浏览器状态 AFAICT 的某些变化做出反应)。

基本上,我如何修复我的应用程序以使 Ace 组件工作并接受输入?我的应用程序的完整源代码可在 github 获得。

代码

HTML

angular.html

<div class="content pure-g-r" data-ng-controller="MeteorCtrl">
    <header>
        <nav id="menu" class="pure-menu pure-menu-open pure-menu-fixed pure-menu-horizontal">
            <div class="pure-u-1-5">
                <div class="pure-menu-heading">Meteor-Ace</div>
            </div>

            <ul class="pure-u-4-5">
                <li data-ng-repeat="menuItem in menuItems">
                    <a href="{{menuItem.address}}">{{menuItem.name}}</a>
                </li>
            </ul>
        </nav>
    </header>

    <article id="content">
        <div class="content-ribbon">
                <div data-ng-view></div>
        </div>
        <footer class="pure-u-1">
            Made with the excellent <a href="http://meteor.com/">Meteor</a> framework and
            <a href="http://meteor.com/">AngularJS</a>. © 2013 Arve Knudsen
        </footer>
    </article>
</div>

partials/home.html

<div class="pure-u-1-5">
    <div id="sidebar">Sidebar Content</div>
</div>

<div class="pure-u-4-5">
    <div id="editor-container">
        <h1><a href="http://ace.c9.io/">Ace</a> Editor Demo</h1>

        <div data-ui-ace></div>
    </div>
</div>

咖啡脚本

app.coffee

require(["angular", "underscore"], (angular, _) ->
  homeUrl = "/"

  app = angular.module('meteorapp', ['meteor', 'ui.ace'],
    ['$routeProvider', '$locationProvider', ($routeProvider, $locationProvider) ->
      $routeProvider.when(homeUrl, templateUrl: 'partials/home.html', controller: "MeteorCtrl")
      $routeProvider.otherwise(redirectTo: homeUrl)
      $locationProvider.html5Mode(true)
    ])

  class MenuItem
    constructor: (@name, @address) ->
      @isSelected = false

  app.controller("MeteorCtrl", ["$scope", ($scope) ->
    $scope.menuItems = [
      new MenuItem("Home", homeUrl),
    ]
  ])

  app.controller("HomeCtrl", ["$scope", ($scope) ->
    markSelected($scope, homeUrl)
  ])

  markSelected = ($scope, url) ->
    _($scope.menuItems).each((item) =>
      item.isSelected = item.address == url
    )
)

【问题讨论】:

  • 你能创建一个 plunker 吗?谢谢
  • @sza 到目前为止还没有听说过 Plunker。看看我能做什么。
  • @sza 我不认为 Plunker 是该项目的最佳选择,因为该项目过于依赖 Meteor 框架。我必须在考虑 Plunker 的情况下重写,我不明白这一点,因为该应用程序首先是面向 Meteor 的。

标签: angularjs coffeescript meteor angular-ui ace-editor


【解决方案1】:

问题是编辑器没有正确调整大小。 在ui准备好后尝试更新ace版本或调用editor.resize()

【讨论】:

  • 既然你建议更新 Ace 版本,这个问题在新版本中修复了吗?
  • 新版本修复了一些调整大小的错误。我不能 100% 确定它是否修复了这个特定的错误,因为我无法让您的应用在本地运行,并且在您链接的页面上,所有内容都被压缩在一起并且无法调试。
  • 好的,谢谢,将尝试更新 Ace(尽管这取决于我是否能够更新我正在使用的 Meteor 包)。我还被告知有一个 Meteor 专用版本的 Ace,它可能(?)效果更好。
  • this 似乎使用最新的 ace build
  • 我看的比较详细,觉得不是很有用,基本上是给ace加了一些包装。我还看到,在您的示例中,包括了 ace 目录中的所有文件,这很糟糕,因为 ace 有多种模式。最好让 ace 在需要时加载文件 var config = require("ace/config");config.set("basePath", "js/modules/ace/build/src-min");跨度>
猜你喜欢
  • 2021-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多