2015-02-11 96 views
-1

我的腳本:角功能沒有得到所謂的

var AAMVC = angular.module('AAMVC', []); 
var SportsController = function ($scope, $http) { 
    $http.get("/api/SportApi/Get") 
    .success(function (response) { 
     obj = JSON.parse(response); 
     $scope.sports = angular.fromJson(obj); 

    }); 


     getCountries = function (id) { 
     $http.get("/api/SportApi/GetCountry/") 
     .success(function (response) { 
      obj = JSON.parse(response); 
      $scope.countries = angular.fromJson(obj); 

     }); 

    } 

現在我想從我的MVC頁面CSHTML我打電話功能的getCountries,但沒有任何反應。

<body> 
<div ng-controller="SportsController"> 
    <div style="float:left"> 


     <h3>SPORTS</h3> 

     <table class="CSSTableGenerator"> 
      <tr ng-repeat="s in sports"> 
       <td> 

        <button ng-click="getCountries(s.id)">{{s.name}}</button> 

      </tr> 

      <tr ng-repeat="c in countries"> 
       <td> 
        {{c.name}} 
       </td> 
      </tr> 
     </table> 
    </div> 
</div> 

沒有任何反應,函數不會被調用,該怎麼辦?有一個簡單的解決方法嗎?

+0

你是不是在你的$範圍 – 2015-02-11 14:00:49

+1

$ scope.getCountries創建的getCountries功能是什麼@PatrickEvans談論 – 2015-02-11 14:01:27

+0

哦不錯,這是工作,但ID沒有通過@PatrickEvans – 2015-02-11 14:02:46

回答

2

更換getCountries聲明如下:

$scope.getCountries = function ...