13
我試圖動態添加輸入表單,當「新項目」被點擊。但並不知道如何在js部分編寫代碼。任何想法?如何動態添加輸入表單?
這裏是我的代碼:
<!doctype html>
<html ng-app>
<head>
<title>Angular - My Notes</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
<body>
<h1>My Notes</h1>
<div ng-controller="Note">
<input type="text" placeholder="Question">
<input ng-class="{'blockInput': !inlineChecked}" type="text" placeholder="enter text...">
<input type="checkbox" name="check" value="inline" ng-model="inlineChecked"> Inline
<br>
<button ng-click="add()">New Item</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
<script type="text/javascript">
var Note = function($scope){
// create a variable contain new input forms??
}
</script>
</body>
</html>
需要添加一點點(ng-model on inputs)。例如,在你jsBin中添加'{{items | json}}'並填寫一些表單,你會看到:) – jnthnjns
@Asok如何通過angularjs編輯佔位符值? – Jusleong
@Asok謝謝。我不想添加比原來需要的更多。現在更新。 :) –