admin管理员组

文章数量:1417652

I'm learning google closure, and when I try to use the goog.ui ponent (any class thereof), I get the error goog.require could not find: goog.ui.

My code is:

goog.require('goog.dom');
goog.require('goog.json');
goog.require('goog.events');
goog.require('goog.ui.HoverCard');
goog.require('goog.positioning.AnchoredPosition');
goog.require('goog.positioning.Corner');
goog.require('goog.ui.Component.EventType'); 
goog.require('goog.ui');

The other ponents (at least before I try to load any ui element) work just fine.

Any suggestions on what this could be? I have the version cloned from git about two days ago. I'm not piling, because at this stage I just want to figure out how to write the code.

I'm learning google closure, and when I try to use the goog.ui ponent (any class thereof), I get the error goog.require could not find: goog.ui.

My code is:

goog.require('goog.dom');
goog.require('goog.json');
goog.require('goog.events');
goog.require('goog.ui.HoverCard');
goog.require('goog.positioning.AnchoredPosition');
goog.require('goog.positioning.Corner');
goog.require('goog.ui.Component.EventType'); 
goog.require('goog.ui');

The other ponents (at least before I try to load any ui element) work just fine.

Any suggestions on what this could be? I have the version cloned from git about two days ago. I'm not piling, because at this stage I just want to figure out how to write the code.

Share Improve this question asked Feb 1, 2014 at 18:23 MarcinMarcin 49.9k18 gold badges136 silver badges207 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You can use goog.require() on elements that have been provided by a goog.provide() before.

goog.ui is never provided because it's not a ponent or something that you can use directly with "static" methods (Contrary to goog.events that has listen() methods for instance). It's just a naming convention to regroup all visual ponents.

However, you can do a goog.require('goog.ui.Component') or goog.require('goog.ui.Button') for instance.

I was able to eliminate this by:

  1. Loading the base.js file directly from google's git repository: http://closure-library.googlecode./git/closure/goog/base.js;

  2. Eliminating the attempt to require 'goog.ui' separately from any subponent thereof; and

  3. Moving the require calls into the HTML head directly (inside a script tag), rather than having them in a script loaded in the head.

This doesn't seem entirely satisfactory.

本文标签: javascriptGoogle closure googrequire could not find googuiStack Overflow