javascript - How to have seperate link function instance for angular directives? -


i have directive has function in link fires whenever directive element moved. inside link function create random number. hope every directive instance have own randon number value. no matter of directives move print same value random. how can give each directive own instance of random.

look @ console.log('moving', random); inside of drag: function().. inside setpixelsnap function.

my directive

'use strict'; var cell_length = 80; var colors = ['#ef5350', '#7e57c2', '#ec407a', '#42a5f5', '#ffca28'] var app = angular.module('netjamapp');  /* directive listing tracks */ app.directive('myclip', ['$rootscope', 'diffsyncservice',     function($rootscope, diffsyncservice) {         return {             restrict: 'e',             scope: {                 clip: '=',                 ppb: '=',                 project: '=',                 track: '='             },             link: function(scope, element, attrs) {                 var random = math.random() * 100;                 console.log('clip', scope.clip, 'track', scope.track);                 var track = scope.project.tracks[scope.track];                 var clip = track.clips[scope.clip];                 var tracknum = scope.track;                 var clipnum = scope.clip;                  element.css('left', clip.start * cell_length);                 element.css('width', clip.length * cell_length);                 element.css('background', colors[tracknum % colors.length]);                  element.on('mousedown', function() {                     $(this).removeclass('clip');                 });                  element.on('mouseup', function() {                     $(this).addclass('clip');                 })                  scope.$watch('project', function() {                     // track = scope.project.tracks[tracknum];                     // clip = track.clips[clipnum];                     // element.css('left', clip.start * cell_length);                     // element.css('width', clip.length * cell_length);                     // element.css('background', colors[tracknum % colors.length]);                 }, true);                  // todo: dynamicaly adjusting segment after bpm change?                 var trackid = '#track' + (clipnum.tracknum - 1);                 $(function() {                     var pixels_in_beat = scope.ppb;                     var setpixelsnap = function(pixels_in_beat) {                         // console.log('setting clip snapping to', pixels_in_beat, 'pixels');                         $('.draggable').draggable({                             obstacle: ".clip",                             preventcollision: false,                             axis: 'x',                             snapmode: 'inner',                             grid: [pixels_in_beat, 0],                             containment: trackid,                             scroll: true,                             drag: function(event, ui) {                                 clip.start = math.round(ui.position.left / pixels_in_beat);                                 var curr_end = scope.project.clips_end;                                 if (curr_end < clip.start + clip.length) {                                     scope.project.clips_end = clip.start + clip.length;                                     $rootscope.$broadcast('update cells per track');                                 }                                 diffsyncservice.update();                                 // console.log(json.stringify(scope.project));                                 console.log('moving', random);                             }                         });                     }                      setpixelsnap(pixels_in_beat);                 })             }         };     } ]); /* directive listing tracks */ 


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -