Angularjs 为什么我的表格提交不起作用?
我只想使用双向绑定通过向列表中添加新元素来更新列表。我不明白为什么我做不到?我是否遗漏了一个主要概念 index.htmlAngularjs 为什么我的表格提交不起作用?,angularjs,Angularjs,我只想使用双向绑定通过向列表中添加新元素来更新列表。我不明白为什么我做不到?我是否遗漏了一个主要概念 index.html <!DOCTYPE html> <html> <head> <title>NgRailsTodoList</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
<!DOCTYPE html>
<html>
<head>
<title>NgRailsTodoList</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body ng-app="todoApp" ng-controller="MainCtrl">
<div class="container">
<div class="content-container clearfix">
<div class="col-md-12">
<h1 class="content-title text-center">Todo</h1>
<div ng-repeat="list in lists">
<h3>{{list.name}}</h3>
<div ng-repeat="task in list.tasks">
<h5><input type="checkbox" ng-checked="task.completed">{{ task.body }}</h5>
</div>
<div>
</div>
<form ng-submit="addList()">
<input type="text" ng-model="name"></input>
<button type="submit"> New List </button>
</form>
</div>
</div>
</body>
</html>
问题在标记中。
{{task.body}
第二个
应该是一个结束标记
下面是一个工作示例您在console中遇到了什么错误?什么具体不起作用以及期望的结果是什么?
angular.module('todoApp', ['ui.router', 'templates'])
.factory('lists',[ function () {
var o = { lists: [{ name: "groceries", completed: false,
tasks: [{body: "buy fish",completed: true},
{body: "buy sushi",completed: false},
{body: "buy bread",completed: true}]}]
};
return o;
}])
.controller('MainCtrl', [
'$scope','lists',
function($scope,lists){
console.log(lists);
$scope.lists = lists.lists;
$scope.addList = function(){
$scope.lists.push({name: $scope.name, completed: false})
// console.log(this.name);
// $scope.name = '';
};
}
]);