2016-12-20 11 views
0

htmlの入力フィールドから値を取得できません。フォームから値を取得できませんundefined [AngularJs]

これは私のhtmlです:

<div class="form-group"> 
 
    <label class="control-label col-sm-2" for="subject">Subject:</label> 
 
    <div class="col-sm-10"> 
 
    <input class="form-control" id="idsubject" ng-model="subject" placeholder="Enter Subject"> 
 
    </div> 
 
</div> 
 
<div class="form-group"> 
 
    <label class="control-label col-sm-2" for="body">Body:</label> 
 
    <div class="col-sm-10"> 
 
    <input class="form-control" id="idbody" ng-model="body" placeholder="Enter Body"> 
 
    </div> 
 
</div>

その後、これは私のコントローラのインサートである:

// insert data 
 
$scope.InsertData = function() { 
 
    var insert = { 
 
    subject: $scope.subject, 
 
    body: $scope.body 
 
    } 
 
    var promiseGet = GetAllEntryService.InsertData(insert); 
 
    GetAllEntry(); 
 
    ClearModels(); 
 
    promiseGet.then(function(pl) { 
 
     $scope.InsertData = pl.data 
 
    }, 
 
    function(errorPl) { 
 
     console.log('Some Error in Getting Records.', errorPl); 
 
    }); 
 
}

しかし、この戻り値ポストlike http://localhost:51458/ServiceRequest.svc/InsertData?subject=undefined&body=undefined

なぜ入力フィールドから値が得られないのかわかりません。

これは私のサービスのインサートである:

this.InsertData = function (ticket, request, category, subCategory, subject, body, assignto, status, fileName, fileContent, fileBinary, isActive, createdBy, aCNo) { 
    return $http.post("http://localhost:51458/ServiceRequest.svc/InsertData?"&subject=" + subject + "&body=" + body); 
}; 

この要素の開発者ネットワークを検査

からの映像出力は、私は私のコードで

enter image description here

+0

制御コードでは、 '$ scope.body'の後にカンマを削除してみてください。 –

+0

私は試してみました。それはまだ@ ShhaohaoLinのようなエラーが働いていません – Stfvns

答えて

1

を欠けているものを私を助けてくださいいくつかの問題があります。まずInsertDataを関数として設定し、後でそれをデータに設定します。

次に、あなたが別々のparamsを取りますが、あなたはそれにオブジェクトを渡してきたあなたのサービスがあります:あなたはこのようにそれを使用しまし必要がありますが

var insert = { 
    subject: $scope.subject, 
    body: $scope.body 
} 
var promiseGet = GetAllEntryService.InsertData(insert); 

this.InsertData = function (ticket, request, category, subCategory, subject, body, ...) 

そして、あなたの使用状況を:

var promiseGet = GetAllEntryService.InsertData(/*ticket goes here*/, ... , $scope.subject, $scope.body, ...); 
+0

ありがとうございました。それは正しく働いている!! @YaserAdelMehraban – Stfvns

関連する問題