草庐IT

ControllerAs

全部标签

javascript - 使用 controllerAs 时访问指令中的父范围

我目前有一个使用父Controller范围内属性的指令:.controller('MainCtrl',function($scope){$scope.name='MyName';}).directive('myDirective',function(){return{scope:true,controller:function($scope){console.log($scope.name);//logs'MyName'}};})现在我要在我的Controller中使用controllerAs语法,但我不知道如何在我的指令的Controller中获取对Controller对象的引用。.

javascript - 使用 ControllerAs 语法的 Firebase 3 向数据绑定(bind)

我正在尝试使用firebase和angularfire进行三向数据绑定(bind)。你可以看到我在Plunker中得到了什么:http://plnkr.co/edit/RGA4jZK3Y6n4RkPCHK37app.js:angular.module('ideaBattle',["firebase"]);服务:angular.module('ideaBattle').constant('FBURL','https://ideabattle.firebaseio.com/').service('Ref',['FBURL',Firebase]).factory('dataBank',fun

javascript - 如何使用 ControllerAs 语法手动更新 AngularJS View ?

我正在开发一个带有可排序、可停靠、可float小部件的仪表板。我正在使用的控件之一在结束body标记之前在DOM底部生成float小部件作为HTML。这有效地从窗口控件中生成它们的Controller范围中删除了在窗口控件中完成的操作。我正在使用可用的controllerAs语法开发此仪表板Controller,但我不知道如何在外部组件执行影响数据的操作时使用此语法有效地更新View风景?注意:这不是我面临的唯一一个迫使我手动更新主视图的问题。页面上其他地方也有执行影响View的操作的指令。理想情况下,我永远不必手动更新View,因为我将使用在影响摘要循环的内置Angular命令中发生

javascript - 使用 controllerAs 语法时将当前范围传递给 modalInstance

我使用controllerAs语法来避免在我的Controller中出现$scopesoup,并且还使用ui.bootstrap来呈现模态视图。我需要打开一个与当前Controller共享相同范围的modalInstace。注入(inject)范围时,您可能会执行以下操作:varmodalInstance=$uibModal.open({templateUrl:'addEditModal.html',scope:$scope});但是,由于我没有注入(inject)作用域,而是使用controllerAs语法,所以这将不起作用。根据我的发现,您将需要使用resolve来传递数据,但您必

javascript - 使用 controllerAs 的指令中的 angularjs Controller 无法工作?

我正在尝试将一些数据放入我的指令创建的范围内。这是我的jsFiddle.下面的代码运行良好.directive('directive1',function(){return:{scope:true,controller:function($scope){$scope.name='world';}}}){{name}}但是这些代码不起作用.directive('directive2',function(){return:{scope:true,controller:function(){this.name='world';},controllerAs:'testCtrl'}}){{tes