2016-03-25 19 views
0

Bir litlle programm açısal olarak yazarım. URL'ye gittiğimde: http://localhost:8080/api/v1/projects (bir istek isteği), tarayıcıda bir json tablosu görüyorum. Yapmak istediğim şey, bu nesnelerin bir "listesinin" olmasıdır. Ben sadece json için değil, kullanıcılara sunulabilir bir şey demek istiyorum.ng-tıklama açısal olarak nasıl kullanılır

bunlar benim dosyalar şunlardır:

var app = angular.module('app'); 

app.service('apiService', ['$http', function($http) { 
    this.get = function() { 
    return $http.get("http://localhost:8080/api/v1/projects"); 
    }; 
    this.delete = function(id) { 
    return $http.delete("http://localhost:8080/api/v1/projects/{id}", id); 
    } 
    this.post = function(data){ 
    return $http.post("http://localhost:8080/api/v1/projects", data); 
    } 
}]); 

index.js

service.js

index.html index.js ve service.js

app.controller('controller', ['$scope', 'apiService', function($scope, apiService) { 
    var vm = this; 
    var getData = apiService.get().success(function(data) { 
    vm.data = data; 
    }); 
}]); 

index.html

<!DOCTYPE html> 
    <html lang="en" ng-app="myApp"> 
    <head> 
    <meta charset="UTF-8"> 
    <title></title> 
    <script type="text/javavscript" src="angular.min.js"></script> 
    <script type="text/javavscript" src="index.js"></script> 
    <script type="text/javavscript" src="service.js"></script> 
    </head> 
    <body> 

    <div ng-controller="controller as ctrl"> 
    <div ng-repeat="data in ctrl.data">{{data.name}}</div> 
    </div> 

    </body></html> 

ben ng tıklayın (veya sonucunu göstermek için herhangi bir yöntem) Ben yerine URL'min giderseniz belgelerin listesi var benim kodunda içerebilir sadece nasıl olduğunu söyleyebilir json

'un bir listesini görmek Teşekkür ederim!

cevap

0

Sadece bir eyalet kurabilirsiniz. Bu Sonra bir düğmeye yapabilirsiniz .. senin Tamamladılar çalışıyor ama önce https://localhost:8080/home de kullanıcıyı başlayabilir buysa çok emin değil Im ng tıklama:

<input type="submit" ng-click="redirectTo("http://localhost:8080/api/v1/projects")"/> 

Ve denetleyicisi:

app.ctrl('HomeCtrl', ["$scope", "$state", function($scope,$state){ 
    $scope.redirectTo = function(url){ 
    window.location.href = url;//This because i dont know the state your trying to go to.. 
    } 
}]) 

Ve bundan hemen sonra yönlendirme başlayacaktır. Sonra şimdi url'yi göstermek istiyorsanız, bunu şu sayfada yapabilirsiniz:

<input type="submit" 
ng-click="getJSON"/> 

app.controller('JSONCtrl', ["$scope","apiService" function($scope,apiService){ 
    $scope.getJSON = function(){ 
    apiService.get().then(function(sucess){ 
    //Sucess Method.. 
    }).catch(function(err){ 
    //Error.. 
    }) 
    } 
}]) 
İlgili konular