TypeError: $location.path is not a function

<span class="button-icon pull-left" ><i class="ti ti-plus" ng-click="itemOpen()"></i></span>

This is my Html Code.

 $scope.itemOpen=function()
         {
             return $location.path('/ConsultationParameterMaster');
         };

This is my script. And the error is. $location.path is not a function

Upvotes: 3

Views: 6294

Answers (5)

Sajeetharan
Sajeetharan

Reputation: 222682

You need to inject $location in your controller if you are going to do this. where you are missing 'focus' as a parameter

app.controller('sampleController', ['$scope','$http','$location', function($scope,$http,$location) {
 $scope.itemOpen=function()
         {
             return $location.path('/ConsultationParameterMaster');
         };
}

EDIT:

According to your comment,You need to arrange the dependencies,

coreModule.registerController('MedicalRecordsController', ['$rootScope', '$scope', '$sessionStorage', 'Restangular', '$element', '$themeModule', '$filter', '$uibModal', 'gettext', 'focus', '$location', function ($rootScope, $scope, $sessionStorage, Restangular, $element, $themeModule, $filter, $uibModal, gettext,focus,$location)

Upvotes: 7

barış &#231;ıracı
barış &#231;ıracı

Reputation: 1043

app.controller('ctrl', ['$http','$scope','$location', function($http,$scope,$location) {
 $scope.itemOpen=function()
         {
             return $location.path('/ConsultationParameterMaster');
         };
}
<span class="button-icon pull-left" ><i class="ti ti-plus" ng-click="itemOpen()"></i></span>

Upvotes: 1

JLRishe
JLRishe

Reputation: 101728

Your dependencies aren't lined up correctly. You have 'focus' in the dependency list but not in the parameter list, so your $location is actually focus. That's why it doesn't have a .path() method.

To fix, add focus to your parameters:

$modal, gettext, /*-->*/focus/*<--*/, $location)

Upvotes: 0

Raman Sahasi
Raman Sahasi

Reputation: 31891

in your javascript, whereever your angular controller is defined, you need to inject dependency for $location, like this:

app.controller('myCtrl', ['$scope', '$location', function($scope, $location) {
    ...
}

Upvotes: 0

rkrishnan
rkrishnan

Reputation: 806

Your controller should take $location as an argument. If you forgot to inject $location, you obviously can't use it.

Upvotes: 0

Related Questions