所有的我都面臨着一個問題,我希望有人能夠幫助我解決問題。我有一項服務,返回用戶列表並提供相應的鏈接,點擊該鏈接後需要用戶登錄,登錄成功後,用戶纔會看到用戶信息。如何讓用戶點擊此鏈接並使用模板顯示其詳細信息。我想重新使用這個局部模板爲所有用戶如何在Angular Js中點擊動態鏈接時使用不同的模板
例如: 數據:{{user.url}}收益率:http://localhost:5555/user/randi333
數據:{{user.url}}收益率:http://localhost:5555/user/rkds333
<td>{{user.id}}</td>
<td><a ng-href="{{user.url}}">User Details</a></td>
<td>{{user.firstName}}</td>
<td>{{user.lastName}}</td>
<td>{{user.gender | gender}}</td>
<td>{{user.address}}</td>
<td>{{user.city}}</td>
<td>{{user.state}}</td>
<td>{{user.ZipCode}}</td>
<td>{{user.country}}</td>
<td>{{user.enrollmentEntitysCount}}</td>
<td>{{user.telephone}}</td>
</tr>
</tbody>
var consumewebservice = angular
.module("myconsumewebservice", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider
.when("/home", {
templateUrl: "Templates/home.html",
controller: "homeController"
})
.when("/user", {
templateUrl: "Templates/user.html",
controller: "webserviceController"
})
.when("/user/{{hash}}", {
templateUrl: "Templates/userdetails.html",
controller: "webserviceController"
})
})
.controller("webserviceController", function ($scope, $http,$log,$location,$anchorScroll) {
var successfulcallback = function (response) {
$scope.users = response.data;
$log.info(response);
};
var errorcallback = function (response) {
$scope.error = response.data;
$log.error(response);
};
$http.get('/api/users/')
.then(successfulcallback, errorcallback);
$scope.scrollTo = function (firstname) {
$location.hash(firstname);
$anchorScroll();
}
//Scope to change view where we want the data to display
$scope.changeView = function (view) {
$location.path(view); // path not hash
}
$scope.search = function (item) {
if ($scope.searchText == undefined) {
return true;
}
else {
if (item.name.toLowerCase().indexOf($scope.searchText.toLowerCase()) != -1 || item.city.toLowerCase().indexOf($scope.searchText.toLowerCase()) != -1) {
return true;
}
}
return false;
}
$scope.sortColumn = "firstname";
$scope.reverseSort = false;
$scope.sortData = function (column) {
$scope.reverseSort = ($scope.sortColumn == column) ? !$scope.reverseSort : false;
$scope.sortColumn = column;
}
$scope.getSortClass = function (column) {
if ($scope.sortColumn == column) {
return $scope.reverseSort ? 'arrow-down' : 'arrow-up';
}
return '';
}
}
);
當我點擊它帶我到/用戶/ {{名}}鏈接這些都爲不同的用戶名不同,我得到XML結果返回。我需要這個使用模板,當爲任何用戶點擊鏈接時,它將使用它作爲模板並讀取和格式化這些數據....請協助
不清楚具體哪些pr會徽是。應該在URL中使用':routeParam'而不是'{{routeParam}}' – charlietfl
這是一個很棒的指針,實際上讓我看看狀態參數和路由參數...使用路徑參數解決我的問題...我將添加我的解決方案下面 –