未捕获的ReferenceError:在typeahead.js中未定义require:2

时间:2018-03-09 06:59:48

标签: angularjs ui.bootstrap

我使用Ui.bootstrap的typeahead库

时遇到错误
let apiKey = "Your api key here"
let bundleId = "com.Your uniqueBundleId here"
let searchEngineId = "Your searchEngine here"
let serverAddress = String(format: "https://www.googleapis.com/customsearch/v1?q=%@&cx=%@&key=%@","Your query here" ,searchEngineId, apiKey)


let url = serverAddress.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let finalUrl = URL(string: url!)
let request = NSMutableURLRequest(url: finalUrl!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10)
request.httpMethod = "GET"
request.setValue(bundleId, forHTTPHeaderField: "X-Ios-Bundle-Identifier")

let session = URLSession.shared

let datatask = session.dataTask(with: request as URLRequest) { (data, response, error) in
    do{
        if let jsonResult = try JSONSerialization.jsonObject(with: data!, options: []) as? NSDictionary {
            print("asyncResult\(jsonResult)")
        }
    }
    catch let error as NSError {
        print(error.localizedDescription)
    }
}
datatask.resume()

尝试谷歌搜索但没有找到任何帮助,任何帮助将不胜感激

提前致谢

1 个答案:

答案 0 :(得分:0)

要求不在浏览器中工作。基本上需要一个node_module,通过它我们可以访问其他模块或文件。所以如果你在浏览器端使用它,请尝试其他东西,如import或self.import。< / p>

Please refer this stack question and answer by Latheesan

请同时查看require.js。 require.js