정적 데이터를 가져올 때 angular.js에서 목록보기를 만들고 있습니다. 주어진 바이올린에서 list .as를 만들 수 있습니다. http://jsfiddle.net/65Cxv/50/. 그러나 사용자가 버튼을 클릭 할 때 행을 생성해야하는 다른 단어에서 동적으로 행을 생성해야합니다. 동일한 텍스트 예제 ( "목록")이지만 ID가 다른 목록을 생성해야합니다. ( "0", "1", "2"... etc). 목록을 생성 할 수 있습니다. ..? 여기에서 ..
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<button type="button" class="btn btn-primary">Primary</button>
<ul ng-controller="ListController">
<li>
<a ng-click=></a>
</li>
</ul>
</body>
</html>
JS 코드 :
var myApp = angular.module('myApp',[]);
myApp.controller('ListController', function($scope) {
alert('--')
]);
데이터 배열에 새 개체를 푸시하여 데이터 모델에 추가합니다. :
$scope.items = [
{name: 'item1', content: 'content1'},
{name: 'item2', content: 'content2'},
{name: 'item3', content: 'content3'}
];
/* bind this to `ng-model` of 2 inputs in html*/
$scope.activeItem={ name: '', content:''}
$scope.addItem=function(){
$scope.items.push( $scope.activeItem);
$scope.activeItem={} /* reset active item*/
}
HTML 사용
<button ng-click="addItem()">Add</button>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다