草庐IT

angularJs

全部标签

javascript - AngularJS 传递一个作用域变量名作为函数参数

嗨,我还是AngularJs的新手,想知道这是否可行。在我的Controller上,我试图创建一个函数,该函数采用一个字符串参数,该参数将指示调用哪个$http.get。然后我想在我的范围内分配该参数。例如$scope.getpartial=function(partialtype){varpromise="";switch(partialtype){case"account":promise=$http.get("accounturlhere");break;case"contact":promise=$http.get("contacturlhere");break;}promis

javascript - 使用 Angular、Express 和 Jade 刷新特定页面(使用 html5mode)

我正在尝试刷新页面并执行客户端路由以在ng-view中打开模板Index.jadeextendslayouts/defaultblockcontentsection(data-ng-view)script(type="text/javascript").window.user=!{user};default.jadedoctypehtmlhtml(lang='en',xmlns='http://www.w3.org/1999/xhtml',xmlns:fb='https://www.facebook.com/2008/fbml',itemscope='itemscope',itemty

javascript - Angular bind once vs. track by performance

我有一个ng-repeat指令,上面有一些过滤器,每次重复都包含大量DOM。例如:我想提高一点性能,但我想保持双向绑定(bind)。一种方法是通过以下方式插入轨道:ng-repeat='taskintaskstrackbytask.id'另一种方法是在绑定(bind)中使用一次原生绑定(bind):{{::task.name}}显然我不能同时使用它们,因为在这种情况下双向绑定(bind)将不起作用。如何测量DOM重建速度?哪种方式更有效? 最佳答案 这些并不是相互排斥的构造,并且都有不同的用途。使用trackby只是允许Angula

javascript - $http promise 链以错误的顺序运行

我是angularjs的新手。我的目标很简单。我想进行ajax调用以获取数据,完成后,我想进行第二次调用以获取依赖于第一组信息的另一组数据。我正在尝试利用promise机制来做到这一点,这样我就可以利用链接而不是嵌套的ajax调用,并更好地保留拥有独立功能的能力,我可以根据需要将它们结合在一起。我的代码类似于以下内容:varpromiseGetWorkTypes=function($q,$scope,$http){ console.log("promiseGetWorkTypes"); return$q(function(resolve,reject){ $http({ meth

javascript - $q.reject 和处理 AngularJS 链式 promise 中的错误

我无法理解使用链接promise进行错误处理的基本概念。为了学习规则,我写了一个简单的例子,猜猜结果会是什么。但不幸的是,它的行为并不像我想象的那样。我已经阅读了多篇关于该主题的文章,但由于我的英语水平很差,我可能无法获得详细信息。无论如何,这是我的代码:varpromiseStart=$q.when("start");varpromise1=promiseStart.then(function(){returnServiceforpromise1.get();});varpromise2=promise1.then(function(data1){returnServiceforpr

javascript - AngularJS 在应用程序加载后动态添加 ng-include

我有一个带有指令的更新按钮。单击按钮时,目标元素应该会收到一些包含ngInclude元素的新html。它似乎并没有加载文件,它所做的只是包含一个像这样的评论.如果我记录tpl变量我得到{0:,length:1}.这是我的指令和元素生成器代码。指令angular.module('myApp').directive("contentControl",["$compile",function($compile){return{link:function(scope,element,attrs){element.bind("click",function(){var$container=$(t

javascript - AngularJS 获取范围内的选定项

我正在使用Ionic和AngularJS开发应用程序。不知道如何获取所选选项的值Controller.controller('TestCtrl',function($scope,$options){$scope.options=[{id:0,label:'15',value:15},{id:1,label:'30',value:30},{id:2,label:'60',value:60}]$scope.countSelector=$scope.options[0];$scope.changeCount=function(obj){obj=JSON.parse(obj);console.

javascript - 如何在 Angular 中正确实现 DOM 操作?

我最近被指派接管并清理一个已经完成并投入生产的Angular项目。这是我第一次使用Angular。到目前为止我读过的关于Angular的所有内容...https://www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-makehttp://nathanleclaire.com/blog/2014/04/19/5-angularjs-antipatterns-and-pitfalls/http://kirkbushell.me/when-to-use-directives-controllers-or-

javascript - AngularJS $cookies.get() 总是返回 undefined

我正在使用AngularJS1.4.0和$cookies服务。以下代码将始终打印出一个空对象:(function(){varapp=angular.module("user-cookies-service",[]);app.service('UserCookiesService',["$cookies",function($cookies){$cookies.put("Hello","World");console.log($cookies.getAll());}]);})();我试过:使用AngulerJS1.3.15和$cookieStore,当浏览器刷新时cookie不会持续存在

javascript - 如何修复 md-tabs 和 md-toolbar 以及滚动 md-content?

我正在尝试做这样的事情:{{item}}{{item}}我希望选项卡和工具栏固定(始终可见)并滚动列表的内容。我找不到办法做到这一点。还有其他类似的问题报告(例如here),但它们似乎是旧的并且应该已修复。我正在使用angular-material0.10.0笨蛋here 最佳答案 您可以使用一点CSS来做到这一点。Addaclasstotheelementswithposition:fixed!important不要忘记使用!important。这将覆盖选项卡和工具栏的默认位置属性 关