Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用这段代码:
$scope.$watch('message', function() { // the code });
有没有办法手动触发消息的更改事件,所以代码将被执行?
几个选项:
使用 $scope.$apply() 运行调用所有监视表达式的摘要循环
将您的内部手表代码放在一个函数中并手动调用它
改变messages:)
messages
这里的另一个选项是单独声明函数并$scope.watch与指针一起使用。
$scope.watch
var watchFunction = function(){ // the code } $scope.$watch('message',watchFunction); watchFunction();