最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use events in AngularJS Bootstrap Colorpicker - Stack Overflow

programmeradmin5浏览0评论

I can't figure out, how events work with Angular Bootstrap Colorpicker. Here is a Plunker I forked from the developer example. Sadly, the developer made no example for using events.

Events like colorpicker-selected, colorpicker-selected-saturation, colorpicker-selected-hue, colorpicker-selected-alpha, colorpicker-shown, colorpicker-closed should be supported. Just one example would be nice.

Base code without any events:

'use strict';

angular.module('colorApp', ['colorpicker.module'])
  .controller('MainCtrl', ['$scope', function($scope) {

    $scope.nonInput = {
      color: ''
    };

    $scope.resetNonInputColor = function() {
      $scope.nonInput = {
        color: '#ffffff'
      };
    };
}]);

I can't figure out, how events work with Angular Bootstrap Colorpicker. Here is a Plunker I forked from the developer example. Sadly, the developer made no example for using events.

Events like colorpicker-selected, colorpicker-selected-saturation, colorpicker-selected-hue, colorpicker-selected-alpha, colorpicker-shown, colorpicker-closed should be supported. Just one example would be nice.

Base code without any events:

'use strict';

angular.module('colorApp', ['colorpicker.module'])
  .controller('MainCtrl', ['$scope', function($scope) {

    $scope.nonInput = {
      color: ''
    };

    $scope.resetNonInputColor = function() {
      $scope.nonInput = {
        color: '#ffffff'
      };
    };
}]);
Share Improve this question edited Sep 13, 2016 at 17:43 lin asked May 12, 2015 at 13:00 linlin 18.4k4 gold badges66 silver badges87 bronze badges 2
  • Looking at the source code, it seems like a simple $scope.$on('colorpicker-shown', function(){ /* Your code goes here */ }); would work. (However, an ngModel has to be set up on the directive before it fires: github./buberdds/angular-bootstrap-colorpicker/blob/master/… ) – DRobinson Commented May 12, 2015 at 13:05
  • Ohhh yea, its a $rootScope behavior. Please post this as answer, ill mark it as right. Thx m8. This plugin seems not to be patible with angularJS directives. Its a kind of "random" handling. – lin Commented May 12, 2015 at 13:07
Add a ment  | 

1 Answer 1

Reset to default 10

Given that you have an ngModel attached (which seems to be required, per the source code), you simply catch the emitted event with $on in an ancestor of the directive.

$scope.$on('colorpicker-shown', function(event, colorObject){
     console.log(colorObject);
});

All of the events that you asked about (colorpicker-selected-alpha, etc.) are available using their original names.

发布评论

评论列表(0)

  1. 暂无评论