diegonetto / stock-dog

Tutorial on building an Angular application.
47 stars 44 forks source link

$scope.watchlist.addStock is not a function #4

Open aldo86 opened 8 years ago

aldo86 commented 8 years ago

Im getting this error on watchlist.js line 29 when trying to Add a new Stock share to a watchlist

aldo86 commented 8 years ago

Finally got it. After some debugging, I noticed that watchlist Object had a name Conflict with its constructor. So changing the name of the variable to "wlist" solved the problem stockdogbug

jtsnr commented 7 years ago

Good spot!

jtsnr commented 7 years ago

Following on from aldo86's fix, this also means that when you get to the end of Step 7 : Updating the Watchlist View you must add the directive using:

<stk-stock-table ng-show="stocks.length" watchlist="wlist">

qtxplane commented 7 years ago

Agreed good answer, but the "problem" here is more likely to be with the updated yeoman/angular generators. The code that they generate in app.js looks like this:

.when('/watchlist/:listId', {
        templateUrl: 'views/watchlist.html',
        controller: 'WatchlistCtrl'
        controllerAs: 'watchlist'
      })

It is this 'watchlist' here that causes the conflict. The StockDog demo code does not define controllerAs keys:

.when('/watchlist/:listId', {
        templateUrl: 'views/watchlist.html',
        controller: 'WatchlistCtrl'
      })

Therefore no conflict in the demo code! Rather than rename the other 'watchlist' everywhere why not just remove or rename the one offending "controllerAs" key/value?