0

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!

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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){

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.