草庐IT

Level1Controller

全部标签

javascript - 在滚动事件 AngularJS 之后在 Controller 中执行函数

假设我有一个堆叠的文章供稿:{{article.title}}{{article.body}}滚动浏览每篇文章时:...我想执行一个函数:.controller('AppCtrl',['$scope',function($scope){$scope.atNewArticle=function(){console.log(article);}}])我很难找到执行此操作的正确方法,因为我不确定是否应该将滚动事件绑定(bind)到窗口或检测指令元素本身的偏移量。到目前为止,这是我尝试过的:http://jsfiddle.net/6VFJs/1/ 最佳答案

javascript - 在 AngularJS 中使用来自不同 Controller 的 $scope 函数

这个问题在这里已经有了答案:CanoneAngularJScontrollercallanother?(14个答案)关闭9年前。我想在另一个Controller中共享一个Controller的$scope函数,在本例中为AngularUI对话框。特别是在下面的示例中,我希望$scope.scopeVar在PopupCtrl中可用。HereisaPlunkrResolvecodebasedonmlarcher'scommenthere主要.jsangular.module('MyApp',['ui.bootstrap']);varMainCtrl=['$scope','$dialog',

javascript - 为什么每次模型更改时 Angular run controller 都会运行两次?

我的Angular应用程序由以下层组成:service()用于计算和数据处理factory()用作多个Controller的公共(public)数据存储几个controllers()我的Controller公开来自工厂的函数,而工厂又从服务中调用函数。在HTML中,我运行Controller函数并向用户显示输出:{{controller.function()}}。我注意到,当页面加载时,以及每次后续模型更改时,controller.function()都会运行两次。为什么会这样?如何避免不必要的调用?参见workingexample-打开浏览器JS控制台,单击Run并观察console

javascript - 使用 $emit from 指令将事件发送到 Controller

我尝试在选择项目时发送一个事件,使用$emit从指令到Controller。我有两个针对组织的更新功能,另一个针对人员。我的指令应指定应发出哪个事件。这是我的更新函数://组织$scope.updateOrgs=function(selectedVal){}//为人$scope.updatepeople=function(selectedVal,type){}如果是people,我的指令应该为updatepeople()引发一个emit事件,如果是org,它应该引发updateorg()。我的指令是这样的:.directive('search',function($timeout){r

javascript - 直接将服务注入(inject) AngularJS 指令 Controller

我了解Angular依赖注入(inject)如何与指令一起工作,但想澄清一些事情。我有一个虚拟测试指令如下:app.directive("test",[function(){return{restrict:"E",scope:{},controller:["$scope","$filter",function($scope,$filter){varfood=["Applepie","Applecobler","BananaSplit","CherryPie","Applesauce"];$scope.favorites=$filter('filter')(food,"Apple");}

javascript - 从另一个 Controller Angular Js 调用函数

我是使用Angularjs的新手,我已经声明了很多Controller,现在我想将一个Controller的用户功能转换为另一个Controller。这是我的示例代码。app.controller('Controller1',function($scope,$http,$compile){$scope.test1=function($scope){alert("test1");}});app.controller('Controller2',function($scope,$http,$compile){$scope.test2=function($scope){alert("test

javascript - 具有相同 Controller 而不是新 Controller 的 Angular 引导 ui 模式

我正在使用angularbootstrapui模态框,它说要为新Controller提供一个新的$modalInstance。我想在初始化模态框的地方使用同一个Controller。我搜索了但没有成功。我找到了这个链接,但没有成功-Howtousethesamecontrollerformodalandnon-modalforminAngularUIBootstrap?Angular-uibootstrapmodalwithoutcreatingnewcontrollerapp.controller('UserCtrl',['$scope','$filter','ngTablePara

javascript - 如何在 AngularJS Controller 中调用 javascript 函数?

我有以下Javascript函数functionShowProgress(){varmodal=$('');modal.addClass("spinmodal");$('body').append(modal);varloading=$(".loading");loading.show();vartop=Math.max($(window).height()/2-loading[0].offsetHeight/2,0);varleft=Math.max($(window).width()/2-loading[0].offsetWidth/2,0);loading.css({top:to

javascript - 如何从 mvc Controller 获取列表以使用 jquery ajax 查看

我需要从mvcController获取列表以使用jqueryajax查看。我怎样才能做到这一点。这是我的代码。它的警报错误消息。在Controller中publicclassFoodController:Controller{[System.Web.Mvc.HttpPost]publicIListgetFoodDetails(intuserId){IListFoodList=newList();FoodList=FoodService.getFoodDetails(userId);return(FoodList);}}在View中functionGetFoodDetails(){deb

javascript - 将变量从 Controller 范围传递到指令

在我的Controller中,我定义了$scope.worker,这是一个普通的JS对象:{name:'Peter',phone:601002003}我创建了一个指令:.directive('phoneType',[function(){return{restrict:'A',link:function(scope,element,attrs){console.log(attrs);}};}])我的HTML看起来像这样:如何将worker.phone(在此示例中为601002003)从Controller范围传递到指令,以便我可以在link方法中创建我的逻辑?attrs.phoneTy