I'm building a project with angular and php. I have a customer table and I can retrieve all table data, and when I enter a specific customer it shows me only the customer_id and not the rest of customer details. can someone help please?
customerCardDetailsCtrl.js - controller for the page that show all information of a specific customer:
"use strict";
angular.module('dataSystem').controller('customerCardDetailsCtrl', function($scope, $http ,$routeParams, $location) {
var customer_id = $routeParams.customer_id;
$scope.customer_id = customer_id;
$http.get('http://localhost:8081/hamatkin/api/get-allCustomers.php/'+ customer_id).success(function(data){
$scope.customerDetail = data;
});
});
customerCardDetails.html - html page that show only customer_id
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div class="customer">
<h1>כרטיס לקוח</h1>
<a href="/hamatkin/index.html#/customerCards">חזור לרשימת כרטיסי הלקוחות</a>
<h1 ng-bind="customerDetail.customer_id"></h1>
</div>
</body>
</html>
app.js -
.when('/customerCardDetails/:customer_id', {
controller: "customerCardDetailsCtrl",
templateUrl: '../hamatkin/Views/customerCardDetails.html',
screenTitle: "",
costumerHidden: false,
reportsHidden: true,
stockHidden: true,
isIncome_expensesHidden: true,
isNavTabHidden: false,
isFooterHidden: false,
ordersHidden: true
The design is wrong.
In controller- You are using route parameters though they are not on the route url. Your api returns data in customerDetail , this object should be ideally having details of customer you are looking for. So use that in html bindings.
In html - the outer most div is using ng-model , which is wrong as its 2 way binding use ng-bind.
Ng-model has an undefined scope object.
Many more pblms in the code . Review it
Don't know what you're doing with ng-models="customers"
as that variable isn't defined anywhere - you can remove that bit.
The entire block starting from var kind_Of_Customer
and ending with $scope.activePath = null;
can be removed.
You want the data returned from the GET request, so handle it in the GET request's callback. Or you can just replace
<h1>{{customer_id}}</h1>
with
<h1>{{customerDetail.customer_id}}</h1>
.
Or, to avoid {{}}
showing up while the request is loading:
<h1 ng-bind="customerDetail.customer_id"></h1>
(I'd also suggest putting requests like these in a service to separate the two)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.