【问题标题】:ng-click is not giving any response while hitting web aping-click 在点击 web api 时没有给出任何响应
【发布时间】:2018-07-08 08:52:03
【问题描述】:

这里有完整的代码。

<body ng-app="mymodule">
    <label>Search:</label><input type="text" placeholder="Search Here" ng-model="search" />
    <table ng-controller="cntrlbtn" class="table table-bordered">
        <tr ng-repeat="resp in inp">
            <td></td>
        </tr>
    </table>
    <table ng-controller="mycontroller" class="table table-bordered">
        <tr ng-repeat="resp in res | filter :search" >
            <td colspan="1"><input type="button" class="btn btn-danger" value="{{resp.ct_nm}}" ng-click="click(resp.ct_nm);" /></td>       
        </tr>
    </table>
    <span ng-repeat="resp in res" ng-controller="mycontroller">
        <button ng-click="click(resp.ct_nm);">{{resp.ct_nm}}</button>
    </span>
    <table ng-controller="mycontroller" class="table table-bordered">
        <tr ng-repeat="resp in inp">
            <td colspan="1">{{resp.sbct_nm}}</td>
        </tr>
    </table>

角脚本在这里。主要 API 即 http://localhost/Publish/ProductCategory/GET' 正在工作。但第二个 API 即 $scope.click 不工作。在外面测试 API 正在给出值。

在谷歌浏览器开发者工具中,它正在访问 API,但没有得到任何响应。

var appmodule = angular.module('mymodule', []).controller('mycontroller', function ($scope, $http,$location,$anchorScroll) {
  $http.get('http://localhost/Publish/ProductCategory/GET').then(function (response) {
    $scope.res = response.data;
  });

  $scope.click = function (btnval) {
    debugger;
    $http.get('http://localhost/Publish/ProductSubCategory/GET?pdnm=Laptop').success(function (btnres) {
      $scope.inp = btnres;
    });
  };
});

【问题讨论】:

  • 在浏览器中输入,是否有效? 'localhost/Publish/ProductCategory/GET',需要提供端口吗?
  • 是的,它正在浏览器中。
  • 将console.log(btnres) 放在这一行上方 $scope.inp = btnres;你得到了什么?
  • 它没有进入 $http.get();
  • 删除调试器;

标签: javascript jquery angularjs angular-ui-router angularjs-scope


【解决方案1】:

我刚刚尝试了您的代码,它运行良好。但是你需要删除所有额外的

ng-controller="mycontroller"

在您的 html 中,因为它们会导致角度错误,因此它看起来像这样:

<label>Search:</label><input type="text" placeholder="Search Here" ng-model="search" />
    <table class="table table-bordered">
        <tr ng-repeat="resp in inp">
            <td></td>
        </tr>
    </table>
    <table class="table table-bordered">
        <tr ng-repeat="resp in res | filter :search" >
            <td colspan="1"><input type="button" class="btn btn-danger" value="{{resp.ct_nm}}" ng-click="click(resp.ct_nm);" /></td>       
        </tr>
    </table>
    <span ng-repeat="resp in res" >
        <button ng-click="click(resp.ct_nm);">{{resp.ct_nm}}</button>
    </span>
    <table class="table table-bordered">
        <tr ng-repeat="resp in inp">
            <td colspan="1">{{resp.sbct_nm}}</td>
        </tr>
    </table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 2022-01-04
    • 2014-08-15
    • 2014-12-19
    相关资源
    最近更新 更多