user193239
user193239

Reputation: 109

error with the injection angular.js

I have an error with my injection in the controller using angular.js and I know that this is my problem because when I removed ngCookie the error on my console disappeared.

I have read on the web that it is ok the way i'm trying to do it - but for some reason the problem won't go away.

I tried changing the order of ngCookies and ngRoute, tried to write only one of them but I need them both, tried to change my version of angular - but still nothing work. here is my controller

var mymedical = angular.module("mymed",['ngRoute','ngCookies']);

mymedical.controller('getPersonalCtrl',['$scope','$http',function($scope,$http) {
    $http.get("http://localhost:3000/privateData").success(function(data){
        $scope.insertDataToDB = data; 
        console.log(data);
   });

}]);

mymedical.controller('insertPersonalCtrl',['$scope','$http',function($scope,$http){   
                var data = {};      
                data.email = $scope.email;
                data.Tags = $scope.Tags;
                data.title = $scope.title;
                data.Info = $scope.Info;
                data.Category = $scope.Category;
                data.file = $scope.file;
                data.Recommendation = $scope.Recommendation;     
}]);

mymedical.controller('loginCtrl',['$scope','$http','$cookies', function($scope,$http,$cookies){
        var user = {};
        console.log("i'm in the controller of login");
        //user.email = $scope.
        //console.log($scope.email);

        user.email=$scope.myemail;
        user.pass = $scope.pass;

    $scope.putCoockie = function(value){
        var cook=$cookies.get('cookieEmail');
        $cookies.put('cookieEmail',value);
        console.log(value);
       }        

        $http.post('http://localhost:3000/getUser', user).then() 
}]);

how can I solve this?

Upvotes: 0

Views: 50

Answers (2)

Harsh
Harsh

Reputation: 11

Make sure you include ng cookies after ng route in your html page.

I am using the following in my demo project and it is working like charm.

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular-cookies.min.js"></script>

Also, can you show us the error in console?

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222682

Make sure you are loading the correct reference of ngCookies,

  <link rel="stylesheet" href="style.css" />
  <script src="//code.angularjs.org/1.2.14/angular.js"></script>
  <script src="//code.angularjs.org/1.2.13/angular-route.js"></script>
  <script src="//code.angularjs.org/1.2.9/angular-cookies.js"></script>
  <script src="app.js"></script>

DEMO

Upvotes: 1

Related Questions