Closed vieyahn2017 closed 1 year ago
angularjs 获取$scope的几种方法 1 获取dom所在的scope (适用于获取组件的$scope作用域)
2 获取ng-controller获取scope(适用于获取主页面或者入口功能的$scope)
这个帖子跟我用的反而相反?
angular.element('[ng-controller=LUNFeatureCtrl]').scope() angular.element(document.querySelector("#lunGolablNonTWaitngBox")).scope()
try {
xxx = angular;
$scope = angular.element('[ng-controller=examinContentController]').scope();
$scope.saveSwitchScreenCount=function(){ return new Promise((resolve,reject)=>{reject({"data": "filtered", "status": 1});});}
} catch(e) {
}
新的vue的
document.querySelector(".exam-content-container").__vue__.examininfo.subjectList
[Angular2与Angular1的区别]
https://blog.csdn.net/victoryzn/article/details/77099090
第一点:Angular2删掉了$scope的概念。 在ng1.x里面,$scope是一个相当强大又相当可怕的东西,一言不合就让开发者自己$apply。ng2响应社区的强烈吐槽,删除(或者说隐藏) 了$scope这个东西,开发者不再需要感知到它的存在,另外,由于ng2引入了zone.js,所以即使在各种回调函数中修改数据模型也不需要手 动$apply()了。 这一点说明了群众们吐槽的力量还是相当强大的!
第二点:删掉了ng-controller指令。 Controller终于和Component合体了
angular2如何获取?
ng.getComponent https://angular.io/api/core/global/ngGetComponent
测试
window.ng.getComponent(document.querySelector("app-list > ul > li:nth-child(2) > app-list-item"))
ListItemComponent {contactItem: {…}, routerNavigate: EventEmitter, ngContext: LEmbeddedView_ListComponent_li_8(33)}
window.ng.getComponent(document.querySelector("app-list > ul > li:nth-child(2) > app-list-item")).contactItem
{ivd: '', ivdwebMock: '', ivdPackageInstallTime: '', cspHostSshUser: 'cspexpert', ibmcIp: '90.40.111.13', …}
还提到 ng.probe window.ng.probe 我在contacts-demo测的没有
只有当Angular在开发模式下运行时, ng.getComponent()才可用。 https://cloud.tencent.com/developer/ask/sof/106255988
window.getAllAngularRootElements()[0]
enableDebugTools clobbers ng and removes ng.probe https://github.com/angular/angular/issues/12002
https://github.com/rangle/augury/issues/180
// Replace the mutation observer with the ngZone subscribe ( https://github.com/angular/angular/issues/7045)
var ngRootEl = window.getAllAngularRootElements()[0];
var rootNgProbe = window.ng.probe(ngRootEl);
var appRef = rootNgProbe.inject(window.ng.probe.coreTokens.ApplicationRef);
appRef.tick();
var ngZone = rootNgProbe.inject(window.ng.probe.coreTokens.NgZone);
ngZone.onEventDone.subscribe(function() { console.log('Angular did some work'); });
很早的了,居然没记?
https://www.jianshu.com/p/8eba5bb208e9