在 Ember 控制器中包含 Bower 组件

include bower component in Ember Controller

我正在尝试在我的 ember 应用程序中使用 js-beautify。该模块在 ember-cli-build.js 中的 app.import('bower_components/js-beautify/js/lib/beautify.js'); 中导入,但我不知道如何使用 beautify.js。我怎样才能在我的控制器中导入包?我尝试了这样的事情:import Ember from 'ember'; 但是我的 bower_components/js-beautify/js/lib/beautify.js 路线却无法正常工作。

在我在 Ember 中使用的所有外部模块中,一旦将它们添加到 ember-cli-build.js,您就拥有了它们在全局命名空间中导出的对象。

例如,在 ember-cli-build.js:

中添加适当的 app.import 后,我在我的项目中使用 js-cookie
/* globals Cookie */ // This comment makes jshint happy
import Ember from 'ember';

export default Ember.Service.extend({
    saveCookie (name, value) {
        // The Cookie object is available in the global namespace
        Cookie.set(name, value);
    }
});

希望对您有所帮助。

你做对了。但要访问 js_beautify() 使用

window.js_beautify()