2016-08-16 34 views
2

我一直在嘗試過去幾個小時,但因爲我似乎無法弄清楚爲什麼我可以訪問$ scope.FeatureGroup添加到我的網址在keyup上提出API請求,但我不能訪問範圍內的東西

任何想法?

angular.module('ngRepeat', ['ngAnimate',]).controller('repeatController', function($scope, $http) { 
 
    $scope; 
 
    $scope.FeatureGroup = 50000; 
 
    $scope.ShowMeData = function($scope){ 
 
    var url = 'URLHERE' + $scope.FeatureGroup; 
 
    $http.get(url).success(function(data) { 
 
     console.log(data); 
 
     //$scope.Object = data; 
 
    }); 
 
    } 
 
});
<html lang="en"><head> 
 
    <meta charset="UTF-8"> 
 
    <title>Example - example-ng-repeat-production</title> 
 
    <link href="animations.css" rel="stylesheet" type="text/css"> 
 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script> 
 
    <script src="script.js"></script> 
 
    </head> 
 
    <body ng-app="ngRepeat"> 
 
    <div ng-controller="repeatController"> 
 
     There are Features - Please click them to see the page: 
 
     <br><input type="number" ng-model="FeatureGroup" ng-value="10" ng-keyup="ShowMeData()"> 
 
     <br><input type="search" ng-model="q" placeholder="filter Features..." aria-label="filter friends"> 
 
     <ul class="example-animate-container"> 
 
     {{FeatureGroup}} 
 
     <!-- ngIf: Objects.length === 0 --> 
 
     <!-- ngRepeat: feature in Object | filter:q as results --> 
 
     </ul> 
 
    </div> 
 
    </body> 
 
</html>

+0

你試圖從一個'ul'元素中調用'{{FeatureGroup}}'(瀏覽器往往不喜歡這個),試試'div' – Paradoxis

回答

1

這是因爲以下行的。要覆蓋$範圍變量:

$scope.ShowMeData = function($scope){ 

你是真的不傳遞任何範圍變量,而調用函數

ng-keyup="ShowMeData()". 

只是將其更改爲:

$scope.ShowMeData = function(){ 

,它應該工作。

+0

啊你美!非常感謝 :) – Adam91Holt