小编Moh*_*ala的帖子

如何在express/node js中发送错误http响应?

所以在登录页面我发送凭据从angular到express通过get request.What我想做的是,如果在数据库中找到,发送响应并处理角度否则如果没有在db中找到我想快递发送错误响应并处理它角度误差响应函数,但我的代码不工作.

角度控制器:

myapp.controller('therapist_login_controller', ['$scope', '$localStorage', '$http',
  function($scope, $localStorage, $http) {
    $scope.login = function() {
      console.log($scope.username + $scope.password);
      var data = {
        userid: $scope.username,
        password: $scope.password
      };
      console.log(data);
      $http.post('/api/therapist-login', data)
        .then(
          function(response) {
            // success callback
            console.log("posted successfully");
            $scope.message = "Login succesful";
          },
          function(response) {
            // failure callback,handle error here
            $scope.message = "Invalid username or password"
            console.log("error");
          }
        );
    }
  }
]);
Run Code Online (Sandbox Code Playgroud)

APP.js:

  app.post('/api/therapist-login', therapist_controller.login);
Run Code Online (Sandbox Code Playgroud)

控制器:

  module.exports.login = function(req, res) {

    var userid = req.body.userid;
    var password = req.body.password;
    console.log(userid …
Run Code Online (Sandbox Code Playgroud)

get node.js express angularjs

20
推荐指数
2
解决办法
3万
查看次数

以角度js将数据从一个页面传递到另一个页面

如何在角度js中将数据从一个页面传递到另一个页面?我听说过使用某些东西作为服务,但我不知道如何使用它!以下是我想要执行的功能!在第1页:

<div class="container" ng-controller="mycontrl">
  <label for="singleSelect"> Select Date </label><br>
  <select nAMe="singleSelect" ng-model="dateSelect">
    <option value="2/01/2015">2nd Jan</option>
    <option value="3/01/2015">3rd Jan</option>  
  </select>
  <br>
  Selected date = {{dateSelect}}
  <br/><br/><br/>
  <label for="singleSelect"> Select time </label><br>
  <select nAMe="singleSelect" ng-model="timeSelect">
    <option value="9/10">9AM-10AM</option>
    <option value="10/11">10AM-11AM</option>
    <option value="11/12">11AM-12PM</option>
    <option value="12/13">12PM-1PM</option>
    <option value="13/14">1PM-2PM</option>
  </select>
  <button ng-click="check()">Check!</button>
  <br>
  Selected Time = {{timeSelect}}
  <br/><br/>
Run Code Online (Sandbox Code Playgroud)

用户选择时间和日期,用于调用db,结果存储在变量数组中!第1页控制器:

var config= {
  params: { 
    time: times,
    date:dates
  }
};

$http.get('/era',config).success(function(response) {
  console.log("I got the data I requested");
  $scope.therapist_list = response;
});
Run Code Online (Sandbox Code Playgroud)

现在我如何将这个$scope.therapist_list数组变量发送到下一页,该变量将具有不同的控制器,如果使用服务,如何在我的application.js文件中定义它

application.js中:

var …
Run Code Online (Sandbox Code Playgroud)

node.js angularjs

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

angularjs ×2

node.js ×2

express ×1

get ×1