在事件回调中更新模型时更新模型属性对视图没有影响,有什么想法可以解决这个问题吗?
这是我的服务:
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]);
};
}
};
});
Run Code Online (Sandbox Code Playgroud)
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) …Run Code Online (Sandbox Code Playgroud) 我想我在这里缺少一些简单(和重要)的东西.我正在使用一个包含模板的模板,该模板包含一个映射到某个值的输入:
<div ng-controller="Ctrl">
<div ng-include src="'template.html'"></div>
</div>
<!-- template -->
<script type="text/ng-template" id="template.html">
<input ng-model="testvalue" />
</script>
Run Code Online (Sandbox Code Playgroud)
控制器:
function Ctrl($scope) {
$scope.testvalue= "initial value";
}?
Run Code Online (Sandbox Code Playgroud)
警告$ scope.testvalue的值始终显示初始值,而不是更新的值(当您键入输入时).帮助我欧比万.你是我们唯一的希望.