In angularjs I have a kendo ui drop-down list: in my code, when I click on items in the drop-down list, I remove the selected item and add it to a html table (as a row element):
$scope.optionsDropDownListCatalogs = {
dataTextField: "Name",
dataValueField: "Id",
select: onSelect
};
function onSelect(e) {
//Get the selected item
var item = $scope.dropdownlistCatalogs.dataItem(e.item.index());
//Remove it from the dropdownlist
$scope.optionsDropDownListCatalogs.dataSource.remove(item);
//Add the item in the table datasource
$scope.products.push(item);
}
In the html page I have a ng-repeat to show the objects inside the $scope.product
object.
Sometimes the table is updated, sometimes not. If I put $scope.$apply(); at the end of the function the table is (seems to be) updated correctly.
Why must I execute the $apply()
? The push()
doesn't happen in the same digest?