【发布时间】:2014-10-18 04:22:20
【问题描述】:
当我在我的 searchTrails.html 上单击此链接时,我试图在 trailDetails.html 上显示单个跟踪信息。 trailDetails.html 上没有任何内容。但是,如果我将 getDataService.js 中的代码移动到 searchTrailsController.js,一切都会好起来的。我不明白为什么。有人可以提出一些建议吗?
app.js:
var app = angular.module("crowd", ["ngRoute"]);
app.config(function ($routeProvider){
$routeProvider.when("/",{
templateUrl:"views/searchTrails.html",
controller:"searchTrailsCtrl"
});
$routeProvider.when("/trails/:trailId", {
templateUrl: "views/trailDetails.html",
controller: "searchTrailsCtrl"
});
})
getDataService.js:
app.service("dataService", function ($http, $routeParams){
this.getSingleTrail = function (){
var trail = [];
$http.get("http://localhost:8080/DMW-skeleton-1.0/trail/findTrailByTrailId/" + $routeParams.trailId)
.success(function (data){
trail.push(data);
})
return trail
}})
searchTrailsController.js:
app.controller("searchTrailsCtrl", function ($scope, dataService ) {
$scope.trail = dataService.getSingleTrail();})
但是 trailDetails.html 中什么都没有:
<p>{{trail.trailInfo.trailDescription}}</p>
【问题讨论】:
标签: angularjs angularjs-service angularjs-routing