如何在 angularjs 中点击添加条目?
How can I add enteries on click in angularjs?
我正在使用这个 Plunker as a reference. I want to create a similar one however, the change is I want to add a button and on click each entry should be added in the list. I have created this Plunker。但是,我需要在点击时一项一项地添加。我怎样才能做到这一点?不知何故,我在这段代码中做错了什么。
$scope.addRow = function() {
$scope.source.push($scope.counter);
$scope.counter++;
}
如有任何帮助,我们将不胜感激。
您只是将计数器压入数组,您应该压入文本。
angular.module("app", []).controller("MyCtrl", function ($scope) {
$scope.source = [];
$scope.addRow = function(text) {
$scope.source.push(text);
}
});
在您看来:
<div ng-app="app" ng-controller="MyCtrl">
<input type="text" ng-model="some_text"/>
<input type="submit" value="Add" ng-click="addRow(some_text)"/>
</div>
看看这个 Plunker:http://plnkr.co/edit/m1gkM4Yp9xzAa09NDACK?p=preview
为了达到你想要的效果,你需要在更改后调用$scope.source.pageSize(page);,然后$scope.source.refresh() 将此更改应用于源。
angular.module("app", ["kendo.directives"]).controller("MyCtrl", function ($scope) {
var page =1;
$scope.source = new kendo.data.DataSource({
transport: {
read: {
url: "http://demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
}
},
pageSize: page
});
$scope.add= function(){
page++;
$scope.source.pageSize(page);
$scope.source.refresh();
}
});
我正在使用这个 Plunker as a reference. I want to create a similar one however, the change is I want to add a button and on click each entry should be added in the list. I have created this Plunker。但是,我需要在点击时一项一项地添加。我怎样才能做到这一点?不知何故,我在这段代码中做错了什么。
$scope.addRow = function() {
$scope.source.push($scope.counter);
$scope.counter++;
}
如有任何帮助,我们将不胜感激。
您只是将计数器压入数组,您应该压入文本。
angular.module("app", []).controller("MyCtrl", function ($scope) {
$scope.source = [];
$scope.addRow = function(text) {
$scope.source.push(text);
}
});
在您看来:
<div ng-app="app" ng-controller="MyCtrl">
<input type="text" ng-model="some_text"/>
<input type="submit" value="Add" ng-click="addRow(some_text)"/>
</div>
看看这个 Plunker:http://plnkr.co/edit/m1gkM4Yp9xzAa09NDACK?p=preview
为了达到你想要的效果,你需要在更改后调用$scope.source.pageSize(page);,然后$scope.source.refresh() 将此更改应用于源。
angular.module("app", ["kendo.directives"]).controller("MyCtrl", function ($scope) {
var page =1;
$scope.source = new kendo.data.DataSource({
transport: {
read: {
url: "http://demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
}
},
pageSize: page
});
$scope.add= function(){
page++;
$scope.source.pageSize(page);
$scope.source.refresh();
}
});