我有兩個app.js,如frontapp.js和departmentapp.js 在school.html下的SchoolController.js屬於frontapp.js我得到所有學校和部門schoolId,當我點擊DEPARTMENTNAME頁面被重定向到departmenthomepage這是下DepartmentHomeController.js屬於departmentapp.js 任何一個可以建議我怎麼能得到DepartmentID的上DEPARTMENTNAME點擊從一個控制器獲取Id到另一個在angularjs
SchoolController.js
時$scope.getallschools = function() {
SchoolService.getallschools().then(function(response) {
$scope.allschools = response.data;
});
}
在allschoo LS本身我對schoolId
得到有關部門schools.html
<div class="col-xs-12 col-sm-6 col-md-6" data-ng-repeat="school in allschools">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<h5>{{school.schoolName}}</h5>
<ul data-ng-repeat="department in school.departments">
<li><a href="./department"> {{department.departName}}</a></li>
</ul>
</div>
</div>
</div>
DepartmentHomeController.js
$scope.departmentId = 20
DepartmentHomeService.getThemeForDepartment($scope.departmentId)
.then(function(response) {
console.log("received theme");
if(response.data != undefined) {
$scope.cssFile = response.data;
console.log($scope.cssFile);
$('head').append('<link rel="stylesheet" type="text/css" media="screen"
href='+$scope.csspath + $scope.cssFile +'>');
} else {
$('head').append('<link rel="stylesheet" type="text/css" media="screen"
href='+$scope.csspath + $scope.cssFile +'>');
}
});
在這裏,我硬編碼DepartmentID的我怎樣才能得到DepartmentID的動態點擊DEPARTMENTNAME。
如果你有不同的HTML頁面,如[UI路由器(HTTPS使用路由器很多://github.com/angular-ui/ui-router)瀏覽通過ID和其他數據的頁面。如果你只是想之間的控制器使用服務或瀏覽器的localStorage – blewherself