使用$ scope的最佳实践。$ apply();(Best practice of using $scope.$apply(); or even $scope in non-Angular stuff with Angular Component)
根据Kendo的最佳实践 ,Kendo有时需要使用
$scope.$apply();
更新Angular。 Howerver, 新的AngularJS 1.5组件不鼓励使用$scope
。旧控制器 - http://dojo.telerik.com/exok
新1.5组件 - http://plnkr.co/edit/tPTqlzlC9Obn5UFRUqc2?p=preview
为了使上面的代码有效,我必须将它赋给变量。 例如,
var self = this; ... self.firstName = item.firstName;.
var self = this; ... self.firstName = item.firstName;.
我的问题是如何在不使用
$scope.$apply();
情况下正确应用Angular$scope.$apply();
当我们处理剑道甚至是非Angular的东西时,甚至是$scope
。According to Kendo best practices, Kendo sometimes requires to use
$scope.$apply();
to update Angular. Howerver, new AngularJS 1.5 component discourages to use$scope
.Old Controller - http://dojo.telerik.com/exok
New 1.5 Component - http://plnkr.co/edit/tPTqlzlC9Obn5UFRUqc2?p=preview
In order to make the above code to work, I gotta assign this to a variable. For example,
var self = this; ... self.firstName = item.firstName;.
My Question is how we apply Angular correctly without using
$scope.$apply();
or even$scope
when we are dealing with Kendo or even non-Angular stuff.
原文:https://stackoverflow.com/questions/36992137