小编PSL*_*PSL的帖子

鼠标悬停期间附加的跨度上的单击事件未触发

我追加spandivmouseover,我只是想触发嵌套跨度点击.感觉就像我已经尝试了一切运气.

http://jsfiddle.net/NHHSX/1/

我发现了几个类似但不幸的是他们也没有成功.

javascript jquery

5
推荐指数
1
解决办法
300
查看次数

具有服务依赖项的 $log 装饰器会导致循环依赖项错误

在我的应用程序中,我正在编写一个装饰器,$log以便我可以自定义$log包括调用第三方服务的功能。第三方服务$q为其内部活动注入。现在这会导致循环依赖错误:

Uncaught Error: Circular dependency: $q <- tploggerService <- $log <- $exceptionHandler <- $rootScope.

因为qProvider使用exceptionHandlerProvider最终使用logProvider我猜是导致这个的。有没有人在装修时遇到过类似的问题,是否有解决方案或不同的模式来解决这个问题?

这是一个简单的代码演示,感谢您的帮助:

///Some third party APP
angular.module('SomeThirdPartyApp', []);

    tploggerService.$inject = ['$q']; //<-- $q is a dependency

    function tploggerService ($q) {

        this.info = function (data) {
            var deferred = $q.defer(); //Doing something...
            //....
            //....
     };
}

angular.module('SomeThirdPartyApp').service('tploggerService', tploggerService);

///--------------------------------------------------------------------------------
///MY APP
angular.module('decorApp', ['SomeThirdPartyApp']);

 angular.module('decorApp').config([
   '$provide', function ($provide) {
     $provide.decorator('$log', ['tploggerService','$delegate', 
       function (tploggerService, $delegate) { …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

5
推荐指数
1
解决办法
2284
查看次数

无法在嵌套的ngRepeat上触发动画

我无法弄清楚如何使用Angular在嵌套的ngRepeat上触发动画.

CSS类".test"是动画的.在内部ngRepeat上使用".test"时,它不起作用(Plunker):

<div ng-repeat="section in sections">
  <div ng-repeat="item in section.items" class="test">
    <h2>{{item.title}}</h2>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

在外部ngRepeat上使用".test"时,它确实有效(Plunker):

<div ng-repeat="section in sections">
  <div ng-repeat="item in section.items" class="test">
    <h2>{{item.title}}</h2>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

javascript css angularjs angularjs-ng-repeat ng-animate

5
推荐指数
1
解决办法
1150
查看次数

AngularJS karma过滤器未知提供者

我做不到!我只是看了整个互联网,我尝试了其他解决方案,但我无法使其工作.

我有一个过滤器,我想用Karma和Jasmine进行测试.这是我的代码:

app.js:

var services = angular.module('myApp.services', [ 'ngResource' ]);

angular.module('myApp', [
    'ngRoute',
    'myApp.filters',
    'myApp.services',
    'myApp.directives',
    'myApp.controllers'
]).
Run Code Online (Sandbox Code Playgroud)

filters.js

'use strict';

/* Filters */

angular.module('myApp.filters', [])

.filter(
    'lowerAndCapital',
    [ function() {
        return function(text) {
            if (text != undefined) {
                var str = text.toLowerCase();
                var arreglo = str.split(" ");
                var result = "";
                for (var i = 0; i < arreglo.length; i++) {
                    result += " "
                            + arreglo[i].charAt(0).toUpperCase()
                            + arreglo[i]
                                    .substring(1, arreglo[i].length + 1);
                }
                return result;
            }
        }
    }]); …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs karma-runner angularjs-filter karma-jasmine

5
推荐指数
1
解决办法
6174
查看次数

ng-blur不会在父元素上触发

我正在尝试使用ng-blur <tr ng-blur="blurFn()">但它不会触发.它仅在子<input>元素上触发.

这不是特定的<tr><td>.根据Angular 文档,ng-blur模糊事件做出反应,模糊事件不会"冒泡"."焦点"事件泡沫,但没有ng-focusout.

我错过了什么或者我是否需要创建一个新的指令来处理焦点事件?

这是代码片段和小提琴:

HTML

<div ng-app="App">
    <div ng-controller="Ctrl as ctrl">
        <table>
            <tr ng-repeat="item in ctrl.items" ng-blur="ctrl.blurFn()">
                <td><input ng-model="item.A"/></td>
                <td><input ng-model="item.B"/></td>
            </tr>
        </table>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS

angular.module("App", [])
.controller("Ctrl", function(){
    this.blurFn = function($event){
        console.log($event.target);
    };

    this.items = [
        {A: "111", B: "222"},
        {A: "111", B: "222"},
        {A: "111", B: "222"},
        {A: "111", B: "222"},
        {A: "111", B: "222"}
        ];
});
Run Code Online (Sandbox Code Playgroud)

html javascript dom angularjs angularjs-directive

5
推荐指数
1
解决办法
3932
查看次数

AngularJS ng-options将选定项目作为对象

我的范围内有一个对象数组,我将它们列在下面的下拉控件中.

 <select ng-model="selectedItem" ng-options="product.ID as product.Name for product in products">
     <option value="">Please select a product...</option>
 </select>
Run Code Online (Sandbox Code Playgroud)

我还希望将selectedItem作为对象来获取对象的其他属性,以便我可以在页面中进行内容管理.例如;

<a ng-show="selectedItem.isAvailable">Buy Now!</a>
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?谢谢.

angularjs angularjs-ng-options angularjs-ng-model

5
推荐指数
1
解决办法
1万
查看次数

如何在不改变ng-repeat的$ index的情况下使用ng-filter?

目前,如果我过滤,$ index也会更新.因此,如果有500个结果,我过滤排名,也会更新.如何使索引列不更新?

这是我的代码:

<input ng-model="query.teamName" /></div>
<table class="table">
  <thead>
    <tr>
      <th>Rank</th>
      <th>Team</th>
      <th>Location</th>
      <th>Score</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="team in teams | filter:query | orderBy:orderByScore:reverseSort">
      <td><span style="color:white">{{$index+1}}</span></td>
      <td>{{team.teamName}}</td>
      <td>{{team.teamLocation}}</td>
      <td>{{team.teamPoints | number:2}}</td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

控制器:

scoreboard.controller('scoreboardCtrl', function ($scope, $filter) {

     $scope.orderByScore = 'teamPoints';
     $scope.reverseSort = true;

     $scope.teams = [
          { "teamName": "motorboat skydive", "teamLocation": "1189 King", "teamPoints": 35.53},
          { "teamName": "the grinders", "teamLocation": "1189 King", "teamPoints": 127.90},
          { "teamName": "team forrec", "teamLocation": "1189 King", "teamPoints": 29.46},
          { "teamName": "bikini …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-ng-repeat angularjs-filter

5
推荐指数
1
解决办法
1544
查看次数

Angular服务缓存一个值

我的服务需要异步检索一个值,但是一旦我拥有它,我想使用该值的缓存版本.

当两个控制器调用此服务时,我希望第一个控制器缓存检索到的值,第二个控制器使用缓存值,但根据日志,我从未找到缓存值.当它运行时,我看到一条日志消息,显示正在缓存的值,然后,当我按照一个角度路由到另一个控制器时,我没有看到服务找到缓存的值.为什么它没有按照我的期望运行**?**

angular.module('myApp.services').factory('Config', function() {

    var Config = { };

    Config.currentYear = function() {
        if (Config._currentYear) {
            // sadly, we never execute here
            console.log("returning cached year");
            return Parse.Promise.as(Config._currentYear);
        }
        return Parse.Config.get().then(function(config) {
            console.log("caching year");
            Config._currentYear = config.get("currentYear");
            return Config._currentYear;
        });
    };

    return Config;

});
Run Code Online (Sandbox Code Playgroud)

一些注意事项:(1)我将缓存的属性命名为_currentYear,添加下划线以避免与函数名冲突.不确定我是否需要这样做.(2)当缓存值时,我返回一个履行的承诺,因此函数总是返回一个promise ...也不确定是否需要它,但认为它不会受到伤害.

javascript promise angularjs parse-platform angularjs-service

5
推荐指数
1
解决办法
429
查看次数

如何将选定的项目从angular-ui下拉列表发送回角度控制器

使用angular-ui,请考虑以下事项:

<div class="btn-group" dropdown is-open="status.isopen">
  <button type="button" class="btn btn-default btn-labeled dropdown-toggle fa fa-location-arrow" dropdown-toggle ng-disabled="disabled">
    Location: {{ loc }} <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu">
    <li ng-repeat="choice in locations">
      <a>{{choice}}</a>
   </li>
  </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

该应用程序:

var app = angular.module('Demo', ['ui.router', 'ui.bootstrap']);

app.controller('CrmCtrl', ['$scope', function ($scope) {
$scope.location = "Sutton Coldfield";
$scope.locations = [
    "Sutton Coldfield",
    "Coventry",
    "Redditch",
    "London",
    "Manchester",
    "Sheffield",
    "Dublin"
];
}]);
Run Code Online (Sandbox Code Playgroud)

目的是在用户选择新位置时使选择位置改变.即下拉开始像'位置:萨顿科尔菲尔德',并应更新为'位置:考文垂'.我可能还想使用侧边栏中的值.

示例和插件:http://plnkr.co/edit/5giYygkYcVDJ6RvCKRMv?p = preview

为了达到这个目的,我可以更新,$scope.loc但我无法弄清楚的是如何将所选择的选项"连线"或"推"回控制器.

我也在寻找一种最好的练习方式,因为我这样做主要是为了我个人的学习.

我已经看到关于在A元素上使用ng-model的一些讨论,但它没有被采纳.

html javascript angularjs angular-ui angular-ui-bootstrap

5
推荐指数
1
解决办法
2923
查看次数

Angularjs测试返回静态数据的简单工厂

你如何在AngularJs中模拟一个简单的Factory,它在Karma单元测试中返回静态数据?

我有这个简单的工厂,为了示例返回静态数据:

angular.module('conciergeApp.services')
       .factory('CurrentUser', function() {
        return {
            id: 1,
            hotel_id: 1,
        }
      });
Run Code Online (Sandbox Code Playgroud)

我想知道如何为此编写Karma测试?

到目前为止,我有这个代码,但id不起作用:

describe('ReplyCtrl', function() {

    beforeEach(module('conciergeApp'));

    beforeEach(module(function($provide) {
        $provide.service('CurrentUser', function() {
            return 1;
        });
    }));

    //Getting reference of the mocked service
    var mockUtilSvc;

    inject(function(CurrentUser) {
        mockUtilSvc = CurrentUser;
    });

    beforeEach(inject(function($rootScope, $controller) {
        scope = $rootScope.$new();
        ctrl = $controller('ReplyCtrl', {
            $scope: scope
        });
    }));

    it('should return value from mock dependency', inject(function(mockUtilSvc) {
        expect(mockUtilSvc()).toEqual(1);
    }));

});
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误消息:

Firefox 41.0.0 (Mac OS X …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine angularjs karma-runner

5
推荐指数
1
解决办法
786
查看次数