2016-03-31 7 views
0

Hier speichern Sie das ng-Modell ist newattendance in der Datenbank speichern. "Newattendance._id" wird nicht als ng-model.how genommen, um es "newattendance._id" ist ng-Modellng-model Daten nicht erhalten, wenn die Daten gespeichert werden

<select class="form-control" ng-options="item.empcode as item.empcode for item in totemplist" ng-model="item.empcode"> 
       </select> 
<input type="text" ng-repeat="newattendance in totemplist" ng-model="newattendance._id" ng-show="item.empcode ==newattendance.empcode" style="width:200px;" ><br> 
<input placeholder="Enter Attendacne Date" ng-model="newattendance.doa"> 

<button class="btn btn-primary" ng-click="checkOut()">checkOut</button> 

-Controller

EmpMasterController.controller("AttendanceController", ['$scope', 'AttendanceFactory',"EmpAddService", function($scope, AttendanceFactory,EmpAddService){ 
$scope.newattendance={}; 
$scope.totemplist=EmpAddService.getAllEmpAddItems(); 
console.log($scope.totemplist); 
$scope.checkIn = function(){ 
    AttendanceFactory.addAttendance($scope.newattendance); 
    $scope.newattendance = {} 
} 
$scope.getAllAttendance = function(){ 

    console.log("$$$$$"+$scope.newattendance._id) 
    $scope.attendancedetails =AttendanceFactory.getAllAttendance($scope.newattendance._id); 

} 

}])

Fabrik

EmpFactModule.factory("AttendanceFactory", function($resource, RES_URL){ 
var attendanceResource = $resource(RES_URL+"attandence/:id/:attid", 
        {"id": "@id", "attid": "@attid"}, {update: {method: "PUT"}}) 
var attendanceDetails; 
return { 
    addAttendance: function(newattendance){ 
     console.log("..1.. " + newattendance._id) 
     attendanceResource.save({"id":newattendance._id}, newattendance, function(data){ 
      console.log("Add Success ") 
     }, function(data, status){ 
      console.log("Add Failed*****"); 
     }) 
    }, 
    getAllAttendance: function(_id){ 
     console.log("[email protected] " + _id) 
     attendanceDetails = attendanceResource.query({"id": _id}); 
     return attendanceDetails; 
    }, 


} 
}) 

bitte helfen sie mir, wie es als ng-Modell zu machen und wie diese zu retten ...

+1

Sie bitte Ihre vollständigen Code hinzufügen. –

Antwort

0

Ich habe eine JSFiddle für Sie erstellt, die Ihnen hoffentlich hilft, die 2-Wege-Bindung in eckigen zu verstehen.

Sie müssen das Objekt newattendance nicht an die Check-out-Funktion übergeben, es ist bereits auf der scope gespeichert.

HTML:

<div ng-app="app"> 
    <div ng-controller="formValidation"> 
    <div> 
     <div> 
     <span>User Name</span> 
     <input type="text" placeholder="John" ng-model="newattendance._id"> 
     <span> 
      <button ng-click="submit()"> 
      check out 
      </button> 
     </span> 
     </div> 
    </div> 

    <pre>{{newattendance._id}}</pre> 

    </div> 
</div> 

JS:

var app = angular.module('app', []); 

app.controller('formValidation', function($scope) { 

    $scope.submit=function(){ 
    var formPost = { 
     "Username":$scope.newattendance._id 
    }; 
    console.log(formPost); 
    } 

}); 
+0

Danke für Ihre Antwort. Ich kenne diese Zwei-Wege-Bindung. mein Problem ist ng-show mit ng-Modell funktioniert nicht. Ich erhalte Daten aus ausgewählten Optionen und binde die Daten mit ng-show an das Eingabefeld. aber ng-model ist nicht bindend newattendance._id – SrinivasAppQube

+0

Bitte geben Sie die Antwort json, und ich werde meine Antwort entsprechend –

+0

nach API newattendance.Id muss mit ng-Modell senden zu aktualisieren. Überprüfen Sie das Werk beim Speichern. Antwort war 404 Fehler. ich sende die newattendance._id als Handbuch seine Arbeit. – SrinivasAppQube

Verwandte Themen