Where can i access the scope of a loaded controller ? I like to have something like a event after the scope has been initialized for a controller to predefine the model for the view.

我在哪里可以访问加载的控制器的范围?在为控制器初始化范围之后,我希望有类似事件的事件,以便为视图预定义模型。

Is there something like $rootScope.$on("$controllerLoaded")

是否有类似$ rootScope。$ on(“$ controllerLoaded”)

2 个解决方案

#1


1

It's not too clear, but it sounds like you want something to notify another part of an app after a particular controller is loaded. Is that correct?

它不太清楚,但听起来你想要在加载特定控制器后通知应用程序的另一部分。那是对的吗?

If so, you have a couple options. Try looking into $emit. Essentially sends a signal to parent listeners.

如果是这样,你有几个选择。试着查看$ emit。基本上向父听众发送信号。

Here is a write-up of using $emit & $broadcast

这是一个使用$ emit&$ broadcast的文章

$rootScope.$on('emitName', function(){
    //do what you want
});

Another option (more of a hack) would be to set a flag at the end of your controller:

另一种选择(更多的是黑客攻击)是在控制器的末尾设置一个标志:

$rootScope.controllerLoaded = true

Then wherever you are wanting to know when it is done, simply check the $rootScope.controllerLoaded flag.

然后,无论您想知道何时完成,只需检查$ rootScope.controllerLoaded标志即可。

更多相关文章

  1. 选择jquery - 列表未以模态形式加载
  2. Angular 2快速入门 - 我的应用程序组件未加载
  3. 将(重度公式加载的)Excel电子表格转换为用户友好的网络计算器
  4. Nivoslider(在动态ajax内容中)不会在第一次加载时加载图像
  5. 即使通过一系列图像预先加载也表现不佳
  6. 角度连接2控制器通过1服务与ES6语法
  7. 在页面加载时在shadowbox中加载视频
  8. 隐藏加载更多记录按钮ASP.net MVC Ajax Javascript
  9. 利用javascript动态加载头部出现点击事件与hover事件无效解决方

随机推荐

  1. Android多国语言文件夹
  2. Android文件操作的模式
  3. Android 画图常用类
  4. android控件属性(中文)
  5. android相对布局中控件的常用属性
  6. 补间动画
  7. Android Studio下载地址[国内可下载]
  8. Android中Cursor类的概念和用法
  9. Android:获取设备ID、型号等
  10. Android应用开发中半透明效果实现方案