2014-06-07 22 views
0

我正在使用非Angular移动响应框架,我正在尝试将AngularJS数据绑定与它集成。

任何新添加到DOM的内容(添加到Angular之外)都不在Angular的范围内,并且我无法解决如何将它添加到范围中。

这是我到目前为止有:

//non angularJS javascript here... 
var app = framework({ 
    ...., 
    preprocess: function (content, url) { 
     //content variable is the content to be added to the DOM. eg "<div ng-bind...>......</div>" 
     //need to use Angular here to add this new "content" to Angular's scope. 
     return content; //need to return the content so that is gets added to DOM 
    }); 
    .... 
}); 

我将如何添加角到这个预处理功能,将它添加到DOM之前,编制了“内容”?

感谢

回答

0

你必须达到从JS功能范围,并使用$ scope.apply()进行到$ scope变量的任何变化。

var scope = angular.element($("#yourController")).scope(); 

scope.$apply(function(){ 
    scope.hello = 'Hello World'; 
}) 
+0

谢谢......这个实例中的“#yourController”是什么,因为我没有使用Angular控制器将这个内容添加到DOM?它是否包含新的“内容”将被插入到的HTML元素? – Martin

+0

而且,在此阶段(预处理),内容尚未添加到DOM。它在变量“content”preprocess:function(content,url){'所以我们需要在它被Angular编译后返回它,所以框架可以将它添加到DOM。 – Martin

+0

这是你的div元素,你定义了你的ng-controller属性,你的范围被应用。我不确定在使用角度时是否有办法不使用控制器? – Burhan