控制台登录角度

时间:2016-07-10 13:06:43

标签: javascript angularjs controller console.log

我遇到一个问题,我根本没有看到我的控制台日志,我想知道是否有一个管理员在我的控制台中输入我在html页面中的cookie。

var addPartyApp = angular.module('addPartyApp',['ngCookies']);   


addPartyApp.controller('partyController',['$scope','$http', '$cookies', function($scope,$http,$cookies){


console.log("works!");

    //  $scope.createParty = function(){     
               var data = {};      
                data.title = $scope.title;
                data.description = $scope.description;
                data.image = $scope.myFile;
                data.email = $scope.cookie;
                console.log($scope.cookie);
                console.log($scope.myFile);
                console.log(data); 
            $http.post('http://localhost:3000/party', data).then() //callback 
      //}

}]);

我真的很想知道问题是什么,因为我经常使用控制台日志,没有它,我自己很难检查自己

谢谢!

html

<!DOCTYPE html>
<html ng-app="addPartyApp">
 <head>
   <title>show party</title>
   <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
   <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
 </head>
 <body ng-controller="partyController">
  <h1 class="text-center">Add Party</h1>
        <form class="form-group" enctype="multipart/form-data" method="POST" action="http://localhost:3000/party">
          <div class="form-group">
            <div class="col-sm-10">
              <label for="inputEmail3" class="col-sm-2 control-label">Title:</label>
              <input class="form-control" type="text" placeholder="Title" ng-model="title" name="title" required></input>
            </div>
            <div class="col-sm-10">
              <label for="inputEmail3" class="col-sm-2 control-label">Description:</label>
              <textarea class="form-control" id="inputEmail3" type="text" placeholder="Description" ng-model="description" name="description" required></textarea>
              <br>
            </div>
            <div class="col-sm-10">
              <br>
              <input type="file" name="file" accept="image/*" required></input>
            </div>
            <div class="col-sm-10">
              <br>
              <input type="submit" class="btn btn-default" name="send"></input>
            </div>
          </div>
        </form>
    <script src="js/lib/angular/angular.min.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-resource.js"></script>
    <script src="js/addParty.js"></script>
 </body>
 </html>

2 个答案:

答案 0 :(得分:0)

看看这个

addPartyApp.controller('partyController',['$scope','$http',function($scope,$http,$cookies){

你似乎没有在那里注入$ cookies。

试试这个:

addPartyApp.controller('partyController',['$scope','$http', '$cookies', function($scope,$http,$cookies){

这与console.log根本没有关系。这是一个问题,因为您没有执行找到console.logs的代码行

答案 1 :(得分:0)

var addPartyApp = angular.module('addPartyApp', []);


addPartyApp.controller('partyController', ['$scope', '$http',
  function($scope, $http) {


    console.log("works!");

    //  $scope.createParty = function(){     
    var data = {};
    data.title = $scope.title;
    data.description = $scope.description;
    data.image = $scope.myFile;
    data.email = $scope.cookie;
    console.log($scope.cookie);
    console.log($scope.myFile);
    console.log(data);
    $http.post('http://localhost:3000/party', data).then() //callback 
      //}

  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="addPartyApp">

<head>
  <title>show party</title>
</head>

<body ng-controller="partyController">
  <h1 class="text-center">Add Party</h1>
  <form class="form-group" enctype="multipart/form-data" method="POST" action="http://localhost:3000/party">
    <div class="form-group">
      <div class="col-sm-10">
        <label for="inputEmail3" class="col-sm-2 control-label">Title:</label>
        <input class="form-control" type="text" placeholder="Title" ng-model="title" name="title" required />
      </div>
      <div class="col-sm-10">
        <label for="inputEmail3" class="col-sm-2 control-label">Description:</label>
        <textarea class="form-control" id="inputEmail3" type="text" placeholder="Description" ng-model="description" name="description" required></textarea>
        <br>
      </div>
      <div class="col-sm-10">
        <br>
        <input type="file" name="file" accept="image/*" required />
      </div>
      <div class="col-sm-10">
        <br>
        <input type="submit" class="btn btn-default" name="send" />
      </div>
    </div>
  </form>
</body>

</html>

查看angular的依赖注入内联数组注释文档:

https://docs.angularjs.org/guide/di

  

注意保持注释数组与函数声明中的参数同步。

添加'$cookies'

addPartyApp.controller('partyController',['$scope','$http', '$cookies',function($scope,$http,$cookies){