2016-08-14 27 views
0

這是我如何嘗試發送我的文本以上,併發送我的模塊ID到我的js文件。我會喜歡我輸入你寫的文字和你點擊的ID。不會將我的值從按鈕和文本發送到我的js文件

的問題是,它回來,並給了我這樣的:

世界,你好未定義 - 未定義

它看起來會是這樣的:

你好世界3 - Tetetew TWT ewtewt

我想要的是,我需要從按鈕發送LektionerId到我的js文件,同時我發送文本到我的js文件。

JS - 文件位置:

$scope.CheckValue = function() { 
    console.log("Hello world " + $scope.LektionerId + " - " + $scope.Text); 


    //$scope.$watch("OpgaveId", function() { 
    // var url = "/opgaver/CheckOpgave/" + $scope.LektionerId ; 

    // $http.get(url).success(function (response) { 
    //  $scope.Newslist = response; 
    // }); 
    //}); 
} 

的index.html

<div ng-repeat="module in Newslist"> 
     <div class="col-md-8"> 
       <input type="text" 
         ng-model="Text" 
         class="form-control" 
         placeholder="Write your answer here" 
         name="Text" /> 

       <button ng-click="CheckValue()" 
         ng-init="LektionerId='{{module.Id}}'" 
         class="btn btn-primary pull-right" 
         style="margin:6px 0;"> 
        Check your answer 
       </button> 
     </div> 
    </div> 

或者我應該嘗試把它所有的形式?

+0

對於你想在'button'中使用'ngModel'? – developer033

+0

這是一個錯誤。它被帶走。 @ developer033 –

+0

@ J.Petersen你可以嘗試把'CheckValue(name)'給它嗎? – Smit

回答

1

要獲得每個模塊的值,你應該通過這樣的: CheckValue(module)和我會刪除entrirely的ng-inithttps://code.angularjs.org/1.4.12/docs/api/ng/directive/ngInit

大氣壓你在循環中創建的所有輸入字段被綁定到相同型號(ng-model="Text" )。如果你想要不同的值,那麼你將需要提供不同的模型。

<div ng-repeat="module in Newslist"> 
     <div class="col-md-8"> 
       <input type="text" 
         ng-model="module.text" 
         class="form-control" 
         placeholder="Write your answer here" 
         name="Text" /> 

       <button ng-click="CheckValue(module)" 
         class="btn btn-primary pull-right" 
         style="margin:6px 0;"> 
        Check your answer 
       </button> 
     </div> 
    </div> 

$scope.CheckValue = function (module) { 
    console.log("Hello world " + module.id + " - " + module.text); 
} 
+0

你認爲我必須這樣做:' –

+0

您好,我已經提供了示例 – Nora

+0

該文本出現但id'en不會顯示。我不明白。 –

相關問題