Angularjs 在Angular Js中单击时如何为动态链接使用不同的模板
总之,我面临着一个问题,我希望有人能帮我解决。我有一个服务,返回一个用户列表和相应的链接,当点击它需要用户登录,一旦登录成功,用户将显示用户信息。如何允许用户单击此链接并使用模板显示其详细信息。我想为所有用户重复使用此部分模板Angularjs 在Angular Js中单击时如何为动态链接使用不同的模板,angularjs,angularjs-templates,Angularjs,Angularjs Templates,总之,我面临着一个问题,我希望有人能帮我解决。我有一个服务,返回一个用户列表和相应的链接,当点击它需要用户登录,一旦登录成功,用户将显示用户信息。如何允许用户单击此链接并使用模板显示其详细信息。我想为所有用户重复使用此部分模板 <td>{{user.id}}</td> <td><a ng-href="{{user.url}}">User Details</a></td>
<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 '';
}
}
);
例如:
数据:{{user.url}}产生:数据:{{user.url}}产生:
<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 '';
}
}
);
<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 '';
}
}
);
{{user.id}
{{user.firstName}
{{user.lastName}
{{user.gender}性别}
{{user.address}
{{user.city}
{{user.state}
{{user.ZipCode}
{{user.country}
{{user.EnrollmentEntityScont}
{{用户.电话}
var consumerwebservice=angular
.module(“myconsumewebservice”,[“ngRoute”])
.config(函数($routeProvider){
$routeProvider
.when(“/home”{
templateUrl:“Templates/home.html”,
控制器:“家庭控制器”
})
.when(“/user”{
templateUrl:“Templates/user.html”,
控制器:“webserviceController”
})
.when(“/user/{{hash}}”{
templateUrl:“Templates/userdetails.html”,
控制器:“webserviceController”
})
})
.controller(“webserviceController”,函数($scope、$http、$log、$location、$anchorScroll){
var successfulcallback=函数(响应){
$scope.users=response.data;
$log.info(响应);
};
var errorcallback=函数(响应){
$scope.error=response.data;
$log.error(响应);
};
$http.get(“/api/users/”)
.然后(成功回调,错误回调);
$scope.scrollTo=函数(名字){
$location.hash(firstname);
$anchorScroll();
}
//范围以更改要在其中显示数据的视图
$scope.changeView=函数(视图){
$location.path(view);//路径不是散列
}
$scope.search=函数(项){
如果($scope.searchText==未定义){
返回true;
}
否则{
if(item.name.toLowerCase().indexOf($scope.searchText.toLowerCase())!=-1 | | item.city.toLowerCase().indexOf($scope.searchText.toLowerCase())!=-1){
返回true;
}
}
返回false;
}
$scope.sortColumn=“firstname”;
$scope.reverseSort=false;
$scope.sortData=函数(列){
$scope.reverseSort=($scope.sortColumn==列)!$scope.reverseSort:false;
$scope.sortColumn=列;
}
$scope.getSortClass=函数(列){
if($scope.sortColumn==列){
return$scope.reverseSort?'arrow down':'arrow up';
}
返回“”;
}
}
);
当我点击这个链接时,它会将我带到/user/{{username}},对于不同的用户名,它们是不同的,我会得到xml结果。我需要使用一个模板,当为任何用户单击链接时,它将使用该模板作为模板,并读取和格式化这些数据……请在此处协助使用状态引用。将ng href替换为带有stateparms的ui sref
<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 '';
}
}
);
<td>{{user.id}}</td>
<td><a ui-sref="userDetail({userDetail: user})">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>
{{user.id}
用户详细信息
{{user.firstName}
{{user.lastName}
{{user.gender}性别}
{{user.address}
{{user.city}
{{user.state}
{{user.ZipCode}
{{user.country}
{{user.EnrollmentEntityScont}
{{用户.电话}
…并在用户的纵断面图中获取用户对象。好的,我能够解决我的问题,我想在这里发布解决方案。。谢谢各位,你们的指点让我找到了解决方案:
<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 '';
}
}
);
我在路线参数中传递的控制器:
<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 '';
}
}
);
.controller("userdetailsController", function ($scope, $http, $log, $location, $routeParams, ModalService) {
var successfulcallback = function (response, modal) {
$scope.userdetail = response.data;
$log.info(response);
console.log("now on the userdetails controller success")
};
var errorcallback = function (response) {
$scope.error = response.data;
$log.error(response);
};
$http.get('/api/users/'+ $routeParams.id)
.then(successfulcallback, errorcallback);
})
<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 '';
}
}
);
用户控制器
.controller(“userController”、函数($scope、$http、$log、$location、ModalService){
<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 '';
}
}
);
然后在我的配置中,我添加了带有参数的配置
<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 '';
}
}
);
.when("/user/:id", {
templateUrl: "Templates/user-details.html",
controller: "userdetailsController"
})
在我的html模板中,我添加了参数
<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 '';
}
}
);
<tbody>
<tr ng-repeat="user in users">
<td>{{user.id}}</td>
<td> <a href="#/user/{{user.username}}" >{{user.username}}</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>
</table>
{{user.id}
{{user.firstName}
{{user.lastName}
{{user.gender}性别}
{{user.address}
{{user.city}
{{user.state}
{{user.ZipCode}