Axel Avalos
Axel Avalos

Reputation: 31

Problems with AWS and angularjs

I'm working with AWS and angular.

AWS works fine if i have the code in the html file but when I move to an js file it doesn't work.

I have this code:

<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.43.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="myCtrl">
<div id="results"></div>
<input type="file" id="file-chooser" />
<button id="upload-button">Upload to S3</button>
<button ng-click = "listObjs()">Listar</button>
</body>
</html>

and for the js:

(function(){
    var myApp = angular.module('myApp', []);   

    myApp.controller('myCtrl',['AWS','$scope', function myCtrl($scope, AWS){
    AWS.config.update({
    .......

The error that I get is Unknown provider: AWSProvider <- AWS <- myCtrl

Thank you in advance!

Upvotes: 0

Views: 536

Answers (2)

RamblinRose
RamblinRose

Reputation: 4963

You need to add the AWS module to your app module, for example

myApp = angular.module('myApp', ['AWS']);   

Edit: And as noted by Ephapox, correct the order of your controller parameters

myApp.controller('myCtrl',['$scope', 'AWS', function myCtrl($scope, AWS){

Upvotes: 1

Ephapox
Ephapox

Reputation: 827

In your controller the dependency injection array has $scope and AWS out of order.

You have:

myApp.controller('myCtrl',['AWS','$scope', function myCtrl($scope, AWS){
AWS.config.update({

It should be:

myApp.controller('myCtrl',['$scope', 'AWS', function myCtrl($scope, AWS){
AWS.config.update({

The point of the array is to explicitly register your dependencies as a string so that angular knows what they are. You don't always have to provide the array but if you ever minify your code angular won't know what dependencies you're injecting.

Upvotes: 2

Related Questions