【发布时间】:2014-09-19 05:54:29
【问题描述】:
您能告诉我如何在 angulat.js 中动态创建列表。实际上,当用户按下添加按钮并填写字段时,我可以创建列表。 换句话说,每当您填写它生成一行的字段时,请检查此小提琴。当您单击该行时,您可以获得 Id .Fiddle http://jsfiddle.net/wc4Jm/6/ 现在我正在尝试使用引导模型来执行此操作。换句话说,首先单击按钮我会显示一个弹出屏幕,然后有“添加”按钮。单击它会生成行。但我得到“未定义”。我的我将模型 div 插入控制器内?这是 http://jsbin.com/vubojoxo/4/
为什么我会收到此错误? XMLHttpRequest 无法加载 file:///C:/Users/asd/Desktop/angular/angularproject/dialog.html。收到无效回复。因此不允许访问 Origin 'null'。
当我使用 plunker..并在我的桌面上运行时出现此错误.. 我做这个html?
<!doctype html>
<html ng-app="plunker">
<head>
<script src="angular.js"></script>
<script src="ui-bootstrap-tpls-0.2.0.js"></script>
<link href="bootstrap-combined.min.css" rel="stylesheet">
<script src="index.js"></script>
</head>
<body>
<div ng-controller="DialogDemoCtrl">
<a class="btn" data-toggle="modal" href="" ng-click="openPopupScreen()">Add Contend</a>
</div>
</body>
</html>
.... 对话框.html
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h1>Add Element</h1>
</div>
<div class="modal-body">
<form >
<label>Name:</label><input type="text" class="span3" ng-model="activeItem.name"></br>
<label>Content Name:</label><input type="password" class="span3" ng-model="activeItem.content"></br>
<button type="submit" class="btn btn-success" ng-click="addItem()">Add In List</button>
<button type="reset" class="btn ">Clear</button>
</form>
</div>
<div class="modal-footer">
<a class="btn" data-dismiss="modal" aria-hidden="true">close</a>
</div>
js代码:
var myApp = angular.module('plunker', ['ui.bootstrap']);
myApp.controller('DialogDemoCtrl', function($scope,$dialog) {
$scope.items = [];
$scope.activeItem = {
id:'',
name: '',
content: ''
};
$scope.addItem = function () {
$scope.activeItem.id = $scope.items.length + 1;
$scope.items.push($scope.activeItem);
$scope.activeItem = {}; /* reset active item*/
};
$scope.getId = function (item) {
alert('ID: '+item.id);
};
$scope.openPopupScreen = function () {
alert('Check Open pop up screen');
$dialog.dialog({}).open('dialog.html');
};
});
【问题讨论】:
标签: javascript jquery angularjs