Tag: angularjs

空ng-src不会更新图像

我正在使用ng-src指令,以避免浏览器在Angular评估expression式之前请求图像。 如果expression式“image”改变, ng-src={{image}}将更新ng-src={{image}}的src属性。 我误解了为什么如果expression式(“myImage.png”)变为空(“”) ng-src指令不更新图像的path。 当expression式变空时, ng-src属性变为空,但src属性仍然是最后一个已知的src 。 所以它不会更新图像。 为什么src属性没有更新(到一个空的src ),使图像“消失”。 这是一个暴徒 谢谢

使用引导程序崩溃与angularjs

我正在尝试在我的angular度应用程序中包含下面的bootstrap可折叠面板。 然而,当我点击“展开”,angular似乎看到href="#collapseOne" ,然后redirect到主页而不是折叠面板。 我的路由看起来像这样,我认为otherwise({redirectTo: '/home'}); 正在造成这个问题。 有什么build议么? angular.module('App') .config(['$routeProvider', function($routeProvider) { $routeProvider. when('/users', {templateUrl: 'partials/users/user-list.html', controller: 'UserCtrl'}). when('/users/new', {templateUrl: 'partials/users/user-new.html', controller: 'UserNewCtrl'}). when('/users/:userid', {templateUrl: 'partials/users/user-detail.html', controller: 'UserDetailCtrl'}). otherwise({redirectTo: '/home'}); }]); 面板 – <div class="panel-group" id="accordion"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> Expand </a> </h4> </div> <div id="collapseOne" class="panel-collapse collapse in"> […]

运行Karmatesting的angular度错误:HTML5模式需要一个<base>标记

我有一个Rails后端的单页Angular应用程序。 我在我的index.html文件中使用了一个标签,但是当我使用Karma运行我的前端unit testing时,我得到了以下结果: $location in HTML5 mode requires a <base> tag to be present 我在我的主要.js文件中这样做: angular.module('my.module').config( function($locationProvider, $routeProvider) { $locationProvider.html5Mode( true ); } 那么,有什么办法可以在业务实际呈现的页面中注入<base>元素? 否则,在运行unit testing时告诉Angular / Karma忽略这个错误? 更新 这个Google网上论坛线程和这个GitHub问题都描述了这个问题,但是在这两种情况下,解决scheme都是简单地修改Angular的版本。 我已经这样做了,我甚至可以看到angular-mocks.js中默认的baseHref被设置的行。 这是规格问题: describe 'amnResource', -> $compile = null $rootScope = null beforeEach -> module 'ngMock' module 'amn' module 'directive.template.cache' inject([ '$compile', '$rootScope', ($c, $r) -> […]

Angular JSresize的div指令

我的网站将有多个部分,我打算可以resize。 为了做到这一点,我做了一个“可resize”的指令,例如: <div class="workspace" resize="full" ng-style="resizeStyle()"> <div class="leftcol" resize="left" ng-style="resizeStyle()"> 有一个像这样的指令: lwpApp.directive('resize', function ($window) { return { scope: {}, link: function (scope, element, attrs) { scope.getWinDim = function () { return { 'height': window.height(), 'width': window.width() }; }; // Get window dimensions when they change and return new element dimensions // based on attribute scope.$watch(scope.getWinDim, […]

停止在ng-show / ng-hide上发生的Angularanimation

在我的AngularJS应用程序中,我使用fontawesome作为我的加载debugging器: <i class="fa fa-spin fa-spinner" ng-show="loading"></i> 我还使用AngularToaster来处理对ngAnimate有依赖性的通知消息。 当我在AngularJS应用程序中joinngAnimate的时候,它会以怪异的方式animation我的加载旋钮。 我想阻止这种情况的发生,但无法find一种方法来禁用这些装载机上的animation(它也臭得更新我的应用程序中的每一个装载机)。 这里是一个显示我的确切问题的小人物。

错误:预计`2015-05-29T19:06:16.693209Z`为date – Angular

我正在与Django与rest-framework angular应用程序.. 该应用程序从服务器接收它的信息与JSON。其中一个键是created_time …该created_time的值是格式根据iso-8601 ,例如2015-05-29T19:06:16.693209Z 。 在客户端我有一个字段: <input type="time" ng-model="created_time"> 但是当数据到达时,我得到这个错误: Error: [ngModel:datefmt] Expected `2015-05-29T19:06:16.693209Z` to be a date http://errors.angularjs.org/1.3.13/ngModel/datefmt?p0=2015-05-29T19%3A06%3A16.693209Z at REGEX_STRING_REGEXP (angular.js:63) at Array.<anonymous> (angular.js:19807) at Object.ngModelWatch (angular.js:23289) at Scope.$get.Scope.$digest (angular.js:14235) at Scope.$get.Scope.$apply (angular.js:14506) at done (angular.js:9659) at completeRequest (angular.js:9849) at XMLHttpRequest.requestLoaded (angular.js:9790) 我已经尝试了一切:(格式是完全一样的angular度文档中的说明…

angularjs路由unit testing

正如我们在http://docs.angularjs.org/tutorial/step_07中看到的, angular.module('phonecat', []). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}). when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}). otherwise({redirectTo: '/phones'}); }]); build议使用e2etesting进行路由testing, it('should redirect index.html to index.html#/phones', function() { browser().navigateTo('../../app/index.html'); expect(browser().location().url()).toBe('/phones'); }); 不过,我认为'$ routeProvider'configuration是使用单个函数($ routeProvider)完成的,我们应该能够在不涉及浏览器的情况下进行unit testing,因为我认为路由function不需要浏览器DOM。 例如, 当url是/ foo时,templateUrl必须是/partials/foo.html而控制器是FooCtrl 当url是/ bar时,templateUrl必须是/partials/bar.html,而控制器是BarCtrl 这是一个简单的IMO函数,它也应该在一个简单的testing中进行testing,一个unit testing。 我googlesearch这个$ routeProviderunit testing,但没有运气。 我想我可以从这里借用一些代码,但不能做到这一点, https://github.com/angular/angular.js/blob/master/test/ng/routeSpec.js 。

Angularjs – $ rootScope中的指令链接函数

我在问这个问题,因为我不太清楚如何将rootcope作为依赖传递给指令 我有一个指令,需要显示$ rootScope的一些信息… 我以为我需要将$ rootScope传递给一个指令,但是当我写这样的指令似乎工作。 .directive("myBar", function () { return { restrict: "E", transclude: true, replace: true, template: '<div>' + '<span ng-transclude></span>' + '{{rsLabels.welcome}} {{rsUser.firstName}}!' + '</div>' } }) 我什么时候需要这样做? .directive("myBar", function ($rootScope) { return { restrict: "E", transclude: true, replace: true, template: '<div>' + '<span ng-transclude></span>' + '{{rsLabels.welcome}} {{rsUser.firstName}}!' + '</div>' } }) 我可以和如何使用rootScope,如果我需要它在指令的链接function […]

停止angularUI路由器导航,直到承诺解决

我想防止一些闪烁发生时,轨道devise超时发生,但angular度不知道,直到从资源的下一个授权错误。 会发生什么是模板呈现,一些AJAX调用资源发生,然后我们被redirect到轨道deviselogin。 我宁愿做一个ping导轨上的每一个状态的变化,如果rails会话过期,那么我会立即redirect之前,模板呈现。 UI路由器已解决,可以放在每一个路线,但似乎并不DRY。 我拥有的是这个。 但是这个承诺在国家已经过渡之前是不会解决的。 $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){ //check that user is logged in $http.get('/api/ping').success(function(data){ if (data.signed_in) { $scope.signedIn = true; } else { window.location.href = '/rails/devise/login_path' } }) }); 在新模板呈现之前,如何根据promise的结果中断状态转换?

在angularjs中使用JSON漂亮的打印

我怎样才能使用这json漂亮的打印[ http://jsfiddle.net/KJQ9K/ ]与angularJS? 让我们假设myJsonValue是 {a:1, 'b':'foo', c:[false,'false',null, 'null', {d:{e:1.3e5,f:'1.3e5'}}]} 我希望能够在下面使用渲染前(如示例中所示)