2016-07-06 54 views
3

我試圖用node-geocoder,它採用require所以我通過sudo npm install -g browserify安裝browserify,我想我卡上的browserify <some_file>.js -o src/assets/bundle.js捆綁所有。我不知道我應該選擇哪個文件,所以我選擇了是我想用node-geocodercreate.controller.js)最後我加入<script src="bundle.js"></script>index.html 但我仍然得到的ReferenceError的ReferenceError:要求沒有定義 - browserify - 發電機角度

angular.js:13550 ReferenceError: require is not defined 
    at new CreateController 

create.controller.js

(function() { 
    'use strict'; 

    angular 
    .module('untitled') 
    .controller('CreateController', CreateController); 

    /** @ngInject */ 
    function CreateController($http, $log) { 

    var NodeGeocoder = require('node-geocoder'); 

    var options = { 
     provider: 'google', 
     httpAdapter: 'https', // Default 
     apiKey: 'myApiKey', 
     formatter: 'string' 
    }; 

    var geocoder = NodeGeocoder(options); 


    geocoder.geocode('29 champs elysée paris') 
     .then(function(res) { 
     console.log(res); 
     }) 
     .catch(function(err) { 
     console.log(err); 
     }); 

我使用generator-angular 我很新的JS和所有這些框架,所以我希望我張貼所有需要的信息。

+1

所以切入點browserify應該是開始需要依賴的第一個文件。即時通訊不知道你的項目的其餘部分是如何設置的,但我不認爲你只能在一個控制器上使用browserify,並通過腳本標籤包含它,並期望它能與你的應用程序的其餘部分一起工作,而不使用browserify 。同樣看着node-geocoder模塊,它並沒有在客戶端說任何關於它的東西,所以即使你確實得到它的工作,該模塊也可能取決於Node中可用的東西。 –

+0

這是非常重要的信息,有些插件在客戶端不起作用。我想我只是想尋找其他插件或只使用谷歌地理編碼器。現在我認爲我缺乏這方面的經驗。 –

回答

相關問題