javascript - How to find a directive within a controller and update it's data? -


i'm new angularjs , because of couldn't google answer question want refactor app in mvc way until totally become big piece of spaghetti :)

i have directive should indicate number of users in groups logged in right now. looks this:

angular.module('dashboard').directive('indicator',     function($scope) {         var directive = {             restrict: 'e',             scope: { free: '=' },             template: '<div><h3>free<h3><span>{{free}}</span></div>'         };         return directive;     }); 

this number updates instantly when changed group (i'm using signalr that). json i'm getting server when changes looks this

{    groupid: 123,   loggedin: 12,   onpause: 2,   total: 20 } 

so need somehow (as think) find directive displaying data group given id, , update it's scope object. best way that?

<indicator free="freeval"></indicator> 

in view with

$scope.freeval = 25; 

in controller show free25

every time change $scope.freeval - shown value change.

so don't need change scope value directive - pass scope value directive (free="freeval") , change value in scope when new data arrives - value in directive , in view change automatically.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -