Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function AlbumListController doesnt work in 1.4 #1

Open
bhajanpreets opened this issue Dec 21, 2015 · 7 comments
Open

function AlbumListController doesnt work in 1.4 #1

bhajanpreets opened this issue Dec 21, 2015 · 7 comments

Comments

@bhajanpreets
Copy link

I was practicing the live lessons and found that I was unable to run 01_controller.html with Angular 1.4.8.

I had to replace the way function is defined. (I checked https://docs.angularjs.org/tutorial/step_02)

Replaced,

<script type="text/javascript">
    function AlbumListController($scope){
        $scope.albums = [ 
            ... ];
    }
</script>

by

<script type="text/javascript">
    var albumsApp = angular.module( 'albumsApp', [] );
    albumsApp.controller('AlbumListController', function($scope){
        $scope.albums = [ 
            ... ];
    });
</script>

Just adding a comment here hoping that it would help someone who encounters the same issue

@joachimjr
Copy link

@bhajanpreets
thanks for your comment i also faced the same kind of problem

@marcwan
Copy link
Owner

marcwan commented Feb 26, 2016

Hi!

Yes, they changed Angular. You need to do the following now:

albumsApp.controller("AlbumListController", ['$scope', function ($scope) {
   // etc
}]);

You now have to declare which things you want injected when you add it to the module. Unfortunate change, but … survivable.

HTH!

@marcwan
Copy link
Owner

marcwan commented Feb 26, 2016

I'll update the code for all the various samples.

Thanks for pointing that out!

@joachimjr
Copy link

i appreciate your concern. keep on the great work your doing

On Fri, Feb 26, 2016 at 3:32 PM, Marc Wandschneider <
[email protected]> wrote:

I'll update the code for all the various samples.

Thanks for pointing that out!


Reply to this email directly or view it on GitHub
#1 (comment)
.

@eugenevk
Copy link

eugenevk commented Jun 6, 2016

I faced the same issue. I think it's also worth mentioning that in index.html you need to include the app's name in the html tag: <html ng-app="rfpApp">

@eugenevk
Copy link

eugenevk commented Jun 8, 2016

I have another issue. In lesson 5 you are creating the albumservice.js. When I follow this example (have created my own example provider for customers) with this code:

`(function () {

function customerProvider () {

    var customers = [
            { name: 'Customer-1', address: '100, First Street', city: 'New York', country: 'USA', customer_since: '3/31/2016' },
            { name: 'Customer-2', address: 'Hoofdstraat 1092', city: 'Amsterdam', country: 'Netherlands', customer_since: '1/31/2016' },
            { name: 'Customer-3', address: 'Hertenbergstraat 10', city: 'Tervuren', country: 'Belgium', customer_since: '2/28/2016' }
        ];

    this.getCustomers = function () {
        // Return a cloned object of customers
        return JSON.parse(JSON.stringify(customers));

        // This is also possible:
        // return customers;
    };
};

rfpApp.service("customerProvider", customerProvider);

})()`

I get the error message:

Error: customerProvider is undefined @http://localhost:8080/app/controllers/customerListController.js:20:3 h/<.instantiate@http://localhost:8080/js/angular.min.js:41:396

I guess my customerProvider also needs to be defined differently because of the Angular change?? But how?

@marcwan
Copy link
Owner

marcwan commented Jun 8, 2016

Hey Eugene,

Yah, I think it's the same problem; injection works differently now, so your last line should be:

rfpApp.service("customerProvider", [ customerProvider ]);

Give that a try. You can look in the MEAN workshop samples there for how I declare services and template off those too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants