2016-05-24 68 views
0

我遇到問題。當我使用靜態模板上渲染頁面輸入AngularJs的動態ng模型

<form name="AddArticle" ng-submit="addArticle()" class="form add-article"> 
    <input type="text" value="first" init-from-form ng-model="article.text[0]" /> 
    <input type="text" value="second" init-from-form ng-model="article.text[1]" /> 
</form> 

當我做提交表單,我得到的數據:

{text : {0: "first", 1: "second"}} 

但我有動力矩。通過點擊我添加動態input

$(".button").click(function(){ 
    $('.form').append('<input ng-model="article.info" init-from-form type="text" />'); 
}) 

好的。所有附加,但通過提交我仍然沒有動態輸入數據。

請告訴我,如何獲取所有字段?

+1

爲什麼不只是你已經附加在文檔中但它與'隱藏的形式NG - 如果? – Pytth

+0

,因爲這個信息我通過自動完成,並通過點擊我添加輸入的值,我必須在'ng模型中使用,我不能立即添加這個 – ennet

回答

0

第一,不要混合使用jQuery時,你可以使用角。嘗試是這樣的:

視圖

<form name="AddArticle" ng-submit="addArticle()" class="form add-article"> 
    <p ng-repeat="object in data track by $index"> 
     <input type="text" ng-model="object.text" /> 
    </p> 
    </form> 
    <button ng-click="addInput()"> 
    add 
    </button> 
    {{data}} 
</div> 

控制器

angular.module("app", []) 
    .controller("testCtrl", function($scope) { 
    $scope.data = []; 
    $scope.addInput = function() { 
     $scope.data.push({}); 
    } 
    }) 

https://jsfiddle.net/pntd3kaf/