में अद्यतन नहीं किया गया है मॉडल कॉल को अपडेट करने पर मॉडल को अपडेट करने पर दृश्य पर कोई प्रभाव नहीं पड़ता है, इसे ठीक करने के लिए कोई विचार?दृश्य को AngularJS
angular.service('Channel', function() {
var channel = null;
return {
init: function(channelId, clientId) {
var that = this;
channel = new goog.appengine.Channel(channelId);
var socket = channel.open();
socket.onmessage = function(msg) {
var args = eval(msg.data);
that.publish(args[0], args[1]);
};
}
};
});
publish()
समारोह नियंत्रक में गतिशील रूप से जोड़ा गया था:
यह मेरी सेवा है।
नियंत्रक:
App.Controllers.ParticipantsController = function($xhr, $channel) {
var self = this;
self.participants = [];
// here publish function is added to service
mediator.installTo($channel);
// subscribe was also added with publish
$channel.subscribe('+p', function(name) {
self.add(name);
});
self.add = function(name) {
self.participants.push({ name: name });
}
};
App.Controllers.ParticipantsController.$inject = ['$xhr', 'Channel'];
दृश्य:
<div ng:controller="App.Controllers.ParticipantsController">
<ul>
<li ng:repeat="participant in participants"><label ng:bind="participant.name"></label></li>
</ul>
<button ng:click="add('test')">add</button>
</div>
तो समस्या यह है कि बटन पर क्लिक दृश्य अद्यतन करता है ठीक से, लेकिन जब मैं चैनल nothings से संदेश मिलता है, add()
होता भी है फ़ंक्शन को
यह सहायक था, और एक बार मैंने सोचा कि क्यों मैं हा डीओएम/jQuery घटनाओं के मामले में ऐसा करने के लिए, यह मुझे समझ में आया और मैं इसे स्वीकार करने में सक्षम था। – duma
कूल। मुझे नहीं पता था कि आप रूट स्कोप इंजेक्ट कर सकते हैं। – heneryville
'सेटटाइमआउट' कॉलबैक के लिए, '$ टाइमआउट' सेवा का उपयोग करें: https://coderwall.com/p/udpmtq – itghisi