todo的一个简单应用程序,不向视图添加输入值
A simple application of todo not adding input value to view
每次我的控制器在视图中添加新的输入但为空时,我希望它应该添加具有输入值的新输入。
<div class="container">
<h2>My todos</h2>
<form ng-submit="addTodo()" role="form">
<input type="text" ng-model="todo" value="Something" placeholder="Add">
<input type="submit" value="Add">
</form>
<p class="form-group" ng-repeat="todo in todos">
<input type="text" ng-model="todo" class="form-control">
</p>
</div>
The above code has separate temple main.html and calling that code inside index.html
<div ng-include="'views/main.html'" ng-controller="MainCtrl"></div>
然后每当我添加新的todo时,它都会在todo数组列表中添加空白输入和null值。但是当加载模板而不使用ng时,包括它的工作很好。
angular.module('mymailApp')
.controller('MainCtrl', ['$scope', function ($scope) {
$scope.todos = ['Item 1', 'Item 2', 'Item 3', 'Item 4'];
$scope.addTodo = function(){
$scope.todos.push($scope.todo);
$scope.todo = "";
};
}]);
在左侧面板"Frameworks&Extensions"面板中将"onDomReady"更改为"no wrap-in head"
此外,在模块调用中,您希望传递第二个参数,一个包含模块所有依赖项的数组。在您的情况下,一个空数组[]
angular.module('mymailApp',[]).controller(...)
如果没有第二个参数,它假设您正在尝试扩展现有模块,而不是定义新模块。
更新了你的小提琴:http://jsfiddle.net/z2bvx2oh/11/
所以我解决了将控制器调用移动到"main.html"模板的问题,因为ng-include模板不直接调用ng-controller,它应该在模板中使用$routeProvider或controller应该被调用
修改后的代码看起来像这样:
ng controller="MainCtrl"在main.html 内移动
相关文章:
- 在不刷新整个网格的情况下,向Asp.net网格视图添加新行
- 如何将Web视图添加到Appgyver中的视图中
- 列表视图添加另一个不需要的页面项目
- 如何为模式窗口中呈现的部分视图添加滚动条
- AngularJS:尝试以编程方式向视图添加指令
- 即使使用“on”,JQuery 也无法识别通过主干视图添加的元素
- 从木偶中的空视图添加到收藏
- 主干集合视图添加未使用模型调用
- 如何在 ExtJS5 中从控制器向视图添加组件
- 向当前视图添加内容的主干
- 使用JSON和Backbone.js向视图添加值
- Titanium Studio JavaScript-向表视图添加按钮
- todo的一个简单应用程序,不向视图添加输入值
- 将视图添加到角度种子项目
- 在Angular JS中为单个视图添加完整的页面背景
- 从子视图向父视图添加新集合
- 组合优于继承,这是向视图添加额外功能而不诉诸继承的更好方式
- 在Ionic中,如何在for循环的每次迭代后向应用程序视图添加数据
- Joomla将脚本从视图添加到头部脚本的底部
- 如何为视图添加动态事件