I
I
Ivan-P2015-06-25 18:02:17
JavaScript
Ivan-P, 2015-06-25 18:02:17

Why doesn't Angular Controller work in a separate file?

Controller code:

angular.module("sportsStore")
.controller("cartSummaryController", function($scope, cart) {

    $scope.cartData = cart.getProducts();

    $scope.total = function () {
        var total = 0;
        for (var i = 0; i < $scope.cartData.length; i++) {
            total += ($scope.cartData[i].price * $scope.cartData[i].count);
        }
        return total;
    }

    $scope.remove = function (id) {
        cart.removeProduct(id);
    }
});

HTML: I get an
<div ng-controller="cartSummaryController">
error Argument 'cartSummaryController' is not
If I put the controller code in a file with another code troller for this module, then everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan-P, 2015-06-25
@Ivan-P

Problem solved - forgot to include file with controller)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question