函数响应成功时,AngularJS警报警报成功未显示成功div

时间:2018-11-16 19:08:04

标签: javascript angularjs angular-ui-bootstrap

以下是供用户输入其电子邮件地址和学生ID的HTML代码:

<div id="statusScope" class="pos-rel" style="margin:0 auto 50px;" ng-controller="statusController">
  <form class="form-inline text-center" action="">
    <div class="form-group">
      <label for="email">Email address:</label>
      <input type="email" class="form-control" id="email" ng-model="email">
    </div>
    <div class="form-group">
      <label for="sID">Student ID:</label>
      <input type="text" class="form-control" id="sID" ng-model="sID">
    </div>
  <br/>
  <br/>
    <button type="button" class="btn btn-primary" ng-click="emailCheck()">E-mail Check</button>
  </form>
  <div class="alert alert-success" ng-if="msg.success">{{msg.success}}</div>
  <!-- <div class="col-lg-12 col-sm-12 col-xs-12 alert alert-success ng-hide" ng-show="isDisplay"><strong>{{msg.success}}</strong></div> -->

  <div class="alert alert-danger" ng-if="msg.noStudent">{{msg.noStudent}}</div>
  <br>
</div>

下面的代码检查电子邮件地址和学生ID,如果两者均正确,则返回成功,否则,如果细节不匹配,则返回“不正确的细节”。

$scope.emailCheck = function() {
            var _to = $scope.email,
                    _studentID = $scope.sID,
                    _subject = "System Notify.",
                    // _file1 = student[0].tfile1,
                    _msg = "Hello, "+_to+". \r\n"+"Your course enrollment application status is " + "$('#status').val()" + ". \r\n";
                    // _file1 = "Your file 1 is "+_tfile1+". \r \n "+ +"$('#tfile1').val()"+ ".";

            var all = [].concat($scope.users.cis300, $scope.users.cis400, $scope.users.cis500);

            var student = all.filter(function(item) {
                return item.email == _to && item.studentid == _studentID;
            });

if(student && student.length) {
                    var _file1 = student[0].tfile;
                    var _file2 = student[0].tfile1;
                    var _file3 = student[0].tfile2;
                    _msg = "Hello, "+student[0].firstname+" "+student[0].middlename+". "+student[0].lastname+". \r\n"+"Your status is " + student[0].status + ". \r\n",
                    // _file1 = student[0].tfile1;
                    console.log(_file1);
                    console.log(_file2);
                    console.log(_file3);
                    console.log(_to);
                    $scope.msg = {};
                    $.post('php/mail.php', 
                    JSON.stringify({
                            'to': _to,
                            'subject': _subject,
                            'file1': _file1,
                            'file2': _file2,
                            'file3': _file3,
                            'msg': _msg

                    }),

                function(response, status) {    
                    console.log(_status);
                    $scope.isDisplay = true;
                        $scope.msg.success = "Success! Check your Email";
                    });
                } else {
                    $scope.msg = {};
                    $scope.msg.noStudent = "Email or Student ID is incorrect.";
                }

当我输入错误的详细信息时,我会立即收到“学生ID或电子邮件不正确”的信息,但是当我输入正确的详细信息时,该电子邮件将发送给用户,但不会发出成功提示。仅在我在“电子邮件”或“学生证”字段中输入内容或进行一些更改后,它才会向我显示成功警报。

1 个答案:

答案 0 :(得分:1)

promise解析不在摘要周期之内,因此Angular不会看到您对const WorkInProgressHLEsDataFilter = () => { const { WorkInProgressHLESearchTerm, WIPHLEsData } = this.state; return WIPHLEsData .filter(issue => { return issue.supNumber && issue.supNumber.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.Airline && issue.Airline.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.Product && issue.Product.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.Title && issue.Title.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.Status && issue.Status.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.DateHLERequestReceived && issue.DateHLERequestReceived.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.HLEDevDays && issue.HLEDevDays.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.HLEClientDays && issue.HLEClientDays.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.DateHLESent && issue.DateHLESent.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.DateHLEApprovedRefused && issue.DateHLEApprovedRefused.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 || issue.Comments && issue.Comments.toLowerCase().indexOf(WorkInProgressHLESearchTerm.toLowerCase()) !== -1 }) .map(issue => ( <tr key={issue.id}> <td><a target="_blank" href={"jira.com/browse/" + issue.supNumber}>{issue.supNumber} </a> </td> <td>{issue.Airline}</td> <td>{issue.Product}</td> <td>{issue.Title}</td> <td>{issue.Status}</td> <td>{issue.DateHLERequestReceived}</td> <td>{issue.HLEDevDays}</td> <td>{issue.HLEClientDays}</td> <td>{issue.DateHLESent}</td> <td>{issue.DateHLEApprovedRefused}</td> <td>{issue.Comments}</td> <td> <Link to={{ pathname: '/WorkInProgressHLEs/supNumber?=' + issue.supNumber, state: { supNumber: issue.supNumber, HLEDevDays: issue.HLEDevDays, HLEClientDays:issue.HLEClientDays, DateHLESent: issue.DateHLESent, DateHLEApprovedRefused: issue.DateHLEApprovedRefused, Comments: issue.Comments, Key: this.state.key, Title: issue.Title } }}> <ButtonToolbar> <Button bsSize="xsmall" bsStyle="primary"> EDIT</Button> </ButtonToolbar> </Link> </td> </tr> )); }; <table> <thead> <th>SUP NUMBER</th> <th>AIRLINE</th> <th>PRODUCT</th> <th>TITLE</th> <th>STATUS</th> <th>DATE HLE REQUEST RECEIVED</th> <th>HLE DEV (DAYS)</th> <th>HLE CLIENT (DAYS)</th> <th>DATE HLE SENT</th> <th>DATE HLE APPROVED / REFUSED</th> <th>COMMENTS</th> <th>EDIT ROW</th> </thead> <tbody> { WorkInProgressHLEsDataFilter() } </tbody> </table> 所做的更改,直到其他因素触发摘要周期为止。您需要将更改包装在// Using a guard statement is a safe way to unwrap optionals guard let text1 = Variable1.text else { return } guard let text2 = Variable2.text else { return } if (Float(text1) > 15) && (Float(text2) < 30) { LblResult.text = "TEXT" } 中,以强制执行摘要循环,并允许Angular查看更改并更新视图。

$scope