Title: angularjs Dependency Injection not properly importing external npm libraries
Tags: javascript;angularjs;dependency-injection
Question: Am newbie to angularjs. Stuck at a very silly point.
I am trying to create a small angular app which should use npm library hidemyass-scraper.
Below is my code :
HTML :
<html&gt;
<head&gt;
<script src=&quot;js/angular.js&quot;&gt;</script&gt;
<script src=&quot;js/google-play-scraper/lib/google-play-scraper.js&quot;&gt;</script&gt;
<script src=&quot;js/mine.js&quot;&gt;</script&gt;
</head&gt;
<body ng-app=&quot;myapp&quot; ng-controller=&quot;mycontroller&quot;&gt;
</body&gt;
</html&gt;
mine.js :
var scraper = angular.module('scraper', []);
scraper.constant('gps', ['$window', function($window) {
return $window.google-play-scraper;
angular.module('myapp',['scraper'])
.controller('mycontroller',['$scope','$window','gps', function($scope,$window,gps){
//var gplay = require('google-play-scraper'); So now gplay should be availale and i cant use require in angularjs
gplay.app({appId: 'com.dxco.pandavszombies'})
.then(function(app){
console.log('Retrieved application: ' + app.title);
.catch(function(e){
console.log('There was an error fetching the application!');
ERROR MESSAGE IN CHROME :
google-play-scraper.js:1 Uncaught ReferenceError: require is not defined
angular.js:13424 ReferenceError: gplay is not defined
at new <anonymous&gt; (mine.js:17)
at Object.invoke (angular.js:4625)
at $controllerInit (angular.js:10027)
at nodeLinkFn (angular.js:8965)
at compositeLinkFn (angular.js:8333)
at publicLinkFn (angular.js:8213)
at angular.js:hendersonthomas@example.org.$eval (angular.js:17025)
at Scope.$apply (angular.js:17125)
at bootstrapApply (angular.js:1713)
What am i doing wrong here....
Comment: Are you sure the node version of this library has all the code you need in its index.js?

Comment: Yes it was initally , It was pointing to other js in lib folder, Updated my question with actual files. The issue is require function is in external npm library google-play-scraper.js . Which calls other js what has many more requires ... any help is appreciated



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2016:00:04/17/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><angularjs><dependency-injection>', 'Title': 'angularjs Dependency Injection not properly importing external npm libraries', 'ViewCount': 94, 'id': 36679400, 'user_AboutMe': None, 'user_AccountId': 1756619.0, 'user_DisplayName': 'sunil', 'user_Reputation': 167.0, 'user_Views': 38.0, 'user_id': 1604500.0}}