hi, I need to prepare a detail form for update. That is to mean, there should be exactly one single record for the detail page. However, I understand I should not use ng-repeat, but what should I use? The result is in my attached screenshot, the form fields has a null replica. How should I remove it?
<html ng-app>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js">
</script>
<script>
function ModifyController($scope, $http) {
$scope.errors = [];
$scope.msgs = [];
// the "6" next line supposed to carry in the record with id=6
$http.get('http://localhost/phalcon1/api/robots/'+6
).success(function(data, status, headers, config) {
$scope.items = data; }
).error(function(data, status, headers, config) {
$scope.errMsg = 'error happened getting robots'; }
);
$scope.update = function() {
// remove all error messages
$scope.errors.splice(0, $scope.errors.length);
$scope.msgs.splice(0, $scope.msgs.length);
$http.put('http://localhost/phalcon1/api/robots/'+$scope.id, {
'id': $scope.id,
'name': $scope.name,
'description': $scope.description,
'type': $scope.type,
'year': $scope.year }
).success(function(data, status, headers, config) {
if (data.msg != '')
{
$scope.msgs=(data.messages);
$scope.msgs.push('1:'+status);
}
else
{
$scope.msgs=(data.messages);
$scope.msgs.push('2:'+status);
} }
).error(function(data, status) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$scope.errors=data.messages;
$scope.errors.push(status);
});
}
}
</script>
<body >
<form ng-controller="ModifyController">
<div id='dv1' >
<ul>
<li class="err" style="color:#ff0000" ng-repeat="error in
errors">
{{ error}} </li>
</ul>
<ul>
<li class="info" style="color:#00ff00" ng-repeat="msg in msgs">
{{ msg}} </li>
</ul>
<h2>Update Form</h2>
<div ng-repeat="robot in items"> <!-- if I should not use
ng-repeat here, then what or how should I write??!! -->
<input type="text" ng-model="robot.id" value="6">
<div>
<label>Robot Name ({{robot.name}})</label>
<input type="text" ng-model="robot.name" placeholder="Robot
Name"
style='margin-left: 22px;'>
</div>
<div>
<label>Robot Description ({{robot.description}})</label>
<input type="text" ng-model="robot.description"
placeholder="Robot Description" style='margin-left:
22px;'>
</div>
<div>
<label>Robot Type ({{robot.type}})</label>
<input type="text" ng-model="robot.type" placeholder="Robot
Type"
style='margin-left: 22px;'>
</div>
<div>
<label>Robot Year ({{robot.year}})</label>
<input type="text" ng-model="robot.year" placeholder="Robot
Year"
style='margin-left: 22px;'>
</div>
</div>
<button ng-click='update();' style='margin-left:
63px;margin-top:10px'>
Update</button>
</div>
</form>
</body>
</html>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
<<attachment: howToMakeAdetailPage.png>>
