AngularJS$非角度Javascript中的complite问题
我正在使用一个非角度移动响应框架,并试图将AngularJS数据绑定与之集成 在Angular之外添加到DOM的任何新添加内容都不在Angular的范围内,我很难确定如何将其添加到该范围中 这就是我到目前为止所做的:AngularJS$非角度Javascript中的complite问题,angularjs,Angularjs,我正在使用一个非角度移动响应框架,并试图将AngularJS数据绑定与之集成 在Angular之外添加到DOM的任何新添加内容都不在Angular的范围内,我很难确定如何将其添加到该范围中 这就是我到目前为止所做的: //non angularJS javascript here... var app = framework({ ...., preprocess: function (content, url) { //content variable is the
//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之前,如何将Angular添加到此预处理函数中以编译内容
谢谢您必须从js函数到达作用域,并使用$scope.apply对$scope变量进行任何更改
var scope = angular.element($("#yourController")).scope();
scope.$apply(function(){
scope.hello = 'Hello World';
})
谢谢…在这个例子中,你的控制器是什么,因为我没有使用角度控制器将这个内容添加到DOM中?新内容将插入到的是包含HTML元素吗?而且,在此阶段,还需要对内容进行预处理,以将其添加到DOM中。它在变量内容预处理中:函数内容、url{因此,我们需要在Angular编译后返回它,以便框架可以将其添加到DOM中。它是您的div元素,您在其中定义了ng控制器属性,应用了您的作用域。我不确定在使用Angular时是否有方法不使用控制器?但是页面上可能有许多ng控制器,因此不确定是哪一个要使用的一个。抱歉,这是AngularJS的新功能