新角度,所以我很抱歉,如果這個問題很愚蠢。通知AngularJS控制器關於來自外部的事件
所以我在做一個應用程序,它的一個部分是角的「範圍」可以這麼說之外,這部分是負責接收傳入消息(XMPP)
再有就是角控制器必須通知收到的消息。我所做的是一個醜陋的解決辦法,但它的工作原理:
view.html:
<button ng-click="refreshLayout()" id="refreshLayoutButton" style="display:none"></button>
controllers.js:
.controller('chatCtrl', function($scope) {
$scope.refreshLayout = function() { ... }
})
outside.js:
if(incomingMessage) {
$("#refreshLayoutButton").click();
// append the message to view.html
}
無論如何排除jQuery?我想從outside.js到chatCtrl發送消息,然後將其發送到view.html
OR
只是通知有關事件,以便它可以調用$ scope.refreshLayout(techincally我可以直接附加傳入的消息到view.html使用jQuery無角,但第一個選項是更優選的)
謝謝你的迴應。如何在角度未定義的地方使用$ broadcast? – mikek
我希望這會做這項工作,而不使用$廣播。 http://stackoverflow.com/questions/15294565/angular-is-it-possible-to-watch-a-global-variable-i-e-outside-a-scope。 – tomepejo