函数不在angularjs文件中运行

时间:2017-07-04 11:35:32

标签: javascript angularjs angular-controller

我的代码位于Angular js文件下面,

ctrl.issuesGridConfig = {
        modelSetName: 'issues',
        serializerChildName: 'issues', //will be prepended with "__" before fields for validation
        actions: {
            addRow: {
                active: function(row) {return !ctrl.readOnly;},
                callback: addIssueRow,
            },
            editRow: {
                active: function(issue){ return issue.provider_issue_code;} ? true : false,
                label:  "View test" : "Edit",
                callback: function(issue){
                    $location.path('/issue/' + issue.provider_issue_code);
                }
            },
            deleteRow: {
                active: function(row) {return !ctrl.readOnly;},
                callback: function(row){
                    _.pull(ctrl.activity.issues, row);
                }
            }
        },

我的问题是 - 在编辑下我正在运行该功能(问题)。它在回调:中工作正常,但对于活动:,它不起作用。我在回调:下获得了 issue.provider_issue_code 的价值,但未在有效下获得。只有当issue.provider_issue_code有一些值时,我才想使active = true。请告诉我这里出了什么问题。

1 个答案:

答案 0 :(得分:0)

那里的代码错误,因为您的错误输入错误,所以有效,因为您在代码中使用三元运算符分配了活动:active = condition?真假; (功能就是那里的条件)

    function getToken(){
    var $username = $('#username');
    var $password = $('#password');
    var us = $username.val();
    var pw = $password.val();
    var user = {
    name: us,
    password: pw
    };
    $.ajax({
    type: 'POST',
    url: 'http://localhost:3000/api/authenticate',
    data: user,
    success: function(resultdata){
      $.ajax({
          type: 'GET',
          url: 'http://localhost:3000/api',
          headers: {"x-access-token": resultdata.token},
          success: function(newData){
              console.log('success');
              //console.log(newData);
              window.location= 'http://localhost:3000/api/'
         }
       });
  },
  complete: function () {
        // Schedule the next request when the current one has been completed

        setTimeout(this.ajaxRequest, 4000);
    }
  });
  }    

应该是

active: function(issue){ return issue.provider_issue_code;} ? true : false,

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator