从$ scope函数调用Action方法()

时间:2016-05-25 10:40:19

标签: javascript angularjs asp.net-mvc

我有一个多级重复手风琴。在页面加载时,第一个手风琴的数据将被绑定。当我点击每个1级手风琴时,应该将唯一ID传递给Action方法,并且下一级手风琴的数据应该绑定。 我无法传递此ID并从角度js控制器调用Action方法。任何人都可以在这里建议我做错了什么。

CSHTML

<div id="itineraryAccordion" ng-repeat="itinerary in item.Itineraries">
<div>
<a data-toggle="collapse" data-parent="#itineraryAccordion" href="#collapseItinerary" aria-expanded="false" class="collapsed" ng-bind="itinerary.Name" data-ng-click="GetSchedule(itinerary.Name)"></a>
</div>
<div id="collapseItinerary" class="panel-collapse collapse" aria-expanded="false">
<div class="box-body">
<div class="box-group" id="scheduleAccordion" ng-repeat="schedule in scheList">
<div>
<a data-toggle="collapse" data-parent="#scheduleAccordion" href="#collapseSchedule" aria-expanded="false" class="collapsed" ng-bind="schedule.ScheduleName" > </a>
</div>

SCRIPT

myApp.controller('layoutController', function ($scope, $http) {
$scope.GetSchedule = function (itineraryName, $scope, $http) {
    alert("Itinerary Id is " + itineraryName);
    $http.get("../SchedulePlan/GetSchedule?itineraryName=" + itineraryName).success(function (response) {
        $scope.scheList = response;
    })
};

在这里,我在Alert()中获取了itineraryName,但在下一行中,$ http.get()无效。

1 个答案:

答案 0 :(得分:0)

试试这个。您不需要将$scope$http服务置于功能中。

 myApp.controller('layoutController', function ($scope, $http) {
  $scope.GetSchedule = function (itineraryName) {
   alert("Itinerary Id is " + itineraryName);
    $http.get("../SchedulePlan/GetSchedule?itineraryName=" + itineraryName).success(function (response) {
    $scope.scheList = response;
  })
 };