Javascript 页面未在AngularJS中更新
我正在创建一个web应用程序,其中有一个页面是home.html和about.html。在home.html中,我有一个用户列表,当他们单击其中一个用户时,它会转到about.html,但不会显示用户信息。谁能检查一下我的代码,看看我做错了什么。提前谢谢 这是我的密码。(home.html) 控制器 家庭控制器 服务Javascript 页面未在AngularJS中更新,javascript,angularjs,Javascript,Angularjs,我正在创建一个web应用程序,其中有一个页面是home.html和about.html。在home.html中,我有一个用户列表,当他们单击其中一个用户时,它会转到about.html,但不会显示用户信息。谁能检查一下我的代码,看看我做错了什么。提前谢谢 这是我的密码。(home.html) 控制器 家庭控制器 服务 正如其他人提到的,您的整个代码都是错误的!但我会尽我所能帮助你 您在LawyerController中没有获取数据的任何方法,因此让我们从以下内容开始: 将app.js中的$rou
正如其他人提到的,您的整个代码都是错误的!但我会尽我所能帮助你 您在LawyerController中没有获取数据的任何方法,因此让我们从以下内容开始: 将app.js中的$routeProvider更改为具有以下方法:
$routeProvider
.when("/lawyer", {
controller: "HomeController",
templateUrl: "partials/home.html"
})
.when("/lawyer/:id", {
controller: "LawyerController",
templateUrl: "partials/about.html",
method: 'lawyerInit'
})
.otherwise({
redirectTo: '/lawyer'
});
然后将您的LawyerController
更改为如下内容:
app.controller('LawyerController', ['$scope', 'people', '$routeParams',
function ($scope, people, $routeParams) {
$scope.lawyerInit = function(){
people.getUserInfo().then(function (response) {
$scope.getAll= people.getUserInfo();
for (var i=0; i<=$scope.getAll.length -1; i++){
if($scope.getAll[i].lawyers.id==$routeParams.id){
$scope.person= $scope.getAll[i];
}
}
console.log($scope.person.lawyers);
}, function (error) {
console.log(error)
});
}
}]);
app.controller('LawyerController',['$scope','people','$routeParams',
功能($scope,people,$routeParams){
$scope.lawyernit=函数(){
people.getUserInfo().then(函数(响应){
$scope.getAll=people.getUserInfo();
对于(var i=0;i您需要共享控制器代码,以了解如何将数据从家中传递到page@EmadDehnavi检查更新的问题LawyerController
的代码在哪里?您在此处仅显示一个控制器,MyCtrl
,并且它甚至没有在这两个路由中使用。仅LawyerController
是我需要你的家庭控制器,LawyerController,因为这样我就可以看到你如何获得userInfo的数据。lawyerswell,about.html页面在点击“用户1”时显示空字段。另外,我不是从json抓取它,而是从后端api抓取它。是的,但api的响应通常大部分是json。当您运行这个console.log($scope.userInfo);在您的家庭控制器中,您可以显示您在console.log中看到的任何内容吗?:Object{data:null,status:-1,config:Object,statusText:“,headers:function}如果您愿意,我们可以聊天?这意味着您没有从api获取数据。
var app = angular.module("Portal", ['ngRoute', 'ui.bootstrap' ]);
app.controller('MyCtrl', function($scope) {
//form setting to true
$scope.inactive = true;
$scope.confirmedAction = function() {
isConfirmed.splice($scope.person.id, 1);
location.href = '#/lawyer';
}
});
app.config(function ($routeProvider) {
$routeProvider
.when("/lawyer", {
controller: "HomeController",
templateUrl: "partials/home.html"
})
.when("/lawyer/:id", {
controller: "LawyerController",
templateUrl: "partials/about.html"
})
.otherwise({
redirectTo: '/lawyer'
});
});
app.controller('LawyerController', ['$scope', 'people', '$routeParams',
function ($scope, people, $routeParams) {
people.getUserInfo().then(function (response) {
$scope.person = people.getUserInfo();
console.log($scope.person.lawyers);
}, function (error) {
console.log(error)
});
}]);
var isConfirmed = false;
app.controller('HomeController', function($scope, people, $http) {
if (!isConfirmed) {
people.getUserInfo().then(function (response) {
$scope.userInfo = response.data;
isConfirmed = $scope.userInfo;
console.log($scope.userInfo.lawyers);
}, function (error) {
console.log(error)
});
}
});
app.factory('people', ['$http', function($http) {
var userInfo = {
getUserInfo: function () {
return $http.get('https://******************');
}
};
return userInfo;
}]);
$routeProvider
.when("/lawyer", {
controller: "HomeController",
templateUrl: "partials/home.html"
})
.when("/lawyer/:id", {
controller: "LawyerController",
templateUrl: "partials/about.html",
method: 'lawyerInit'
})
.otherwise({
redirectTo: '/lawyer'
});
app.controller('LawyerController', ['$scope', 'people', '$routeParams',
function ($scope, people, $routeParams) {
$scope.lawyerInit = function(){
people.getUserInfo().then(function (response) {
$scope.getAll= people.getUserInfo();
for (var i=0; i<=$scope.getAll.length -1; i++){
if($scope.getAll[i].lawyers.id==$routeParams.id){
$scope.person= $scope.getAll[i];
}
}
console.log($scope.person.lawyers);
}, function (error) {
console.log(error)
});
}
}]);