vieyahn2017 / jsup

0 stars 1 forks source link

angular 获取$scope的几种方法 #15

Closed vieyahn2017 closed 1 year ago

vieyahn2017 commented 1 year ago

很早的了,居然没记?

https://www.jianshu.com/p/8eba5bb208e9

vieyahn2017 commented 1 year ago

angularjs 获取$scope的几种方法 1 获取dom所在的scope (适用于获取组件的$scope作用域)

2 获取ng-controller获取scope(适用于获取主页面或者入口功能的$scope)

vieyahn2017 commented 1 year ago

这个帖子跟我用的反而相反?

angular.element('[ng-controller=LUNFeatureCtrl]').scope() angular.element(document.querySelector("#lunGolablNonTWaitngBox")).scope()

vieyahn2017 commented 1 year ago

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) {

}
vieyahn2017 commented 1 year ago

新的vue的

document.querySelector(".exam-content-container").__vue__.examininfo.subjectList
vieyahn2017 commented 1 year ago

[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合体了

vieyahn2017 commented 1 year ago

angular2如何获取?

这边有个讨论 https://www.codenong.com/32052432/

vieyahn2017 commented 1 year ago

ng.getComponent https://angular.io/api/core/global/ngGetComponent

vieyahn2017 commented 1 year ago

测试

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', …}

vieyahn2017 commented 1 year ago

还提到 ng.probe window.ng.probe 我在contacts-demo测的没有

vieyahn2017 commented 1 year ago

只有当Angular在开发模式下运行时, ng.getComponent()才可用。 https://cloud.tencent.com/developer/ask/sof/106255988

vieyahn2017 commented 1 year ago

window.getAllAngularRootElements()[0]

vieyahn2017 commented 1 year ago

enableDebugTools clobbers ng and removes ng.probe https://github.com/angular/angular/issues/12002

vieyahn2017 commented 1 year ago

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'); });
vieyahn2017 commented 10 months ago

https://segmentfault.com/a/1190000016076601 [译] 关于 Angular 依赖注入你需要知道的