These are chat archives for angular/angular.js

14th
Nov 2016
Don Waldo
@dgwaldo
Nov 14 2016 01:21

@mosamy19 Have you tried something like this?

     new webpack.ProvidePlugin({
       jQuery: 'jquery',
       $: 'jquery',
       jquery: 'jquery',
       'window.Tether': 'tether'
     }),

And including jQuery as a node module?

Roshan Bhalla
@rbhalla
Nov 14 2016 11:54
Hey all, I'm having issues with $timeouts running for longer than the time specified. In some cases I set a 2000ms timeout and only 10000ms later does it execute. Anyone experienced something like this before?
Frederik Prijck
@frederikprijck
Nov 14 2016 11:54
Maybe you have long running synchrounus tasks
@rbhalla
Roshan Bhalla
@rbhalla
Nov 14 2016 11:55
If I did, should I expec the app itself to be locking up in other areas (e.g. rendering when changing state?). The app seems to be usable during this time
function getResponse() {
    console.log('start', now());

    return $http({...})
        .then(() => {
            console.log('repeating', now());
            return $timeout(getResponse, 2000);
        });
}
that is essentially what I have
Frederik Prijck
@frederikprijck
Nov 14 2016 11:58
oké
That's obviously gonna take longer than 2sec.
You start the timer, next you start a $http call (which is gonna take several seconds).
Roshan Bhalla
@rbhalla
Nov 14 2016 11:58
between repeating and start why should there be a gap of more than 2s?
Frederik Prijck
@frederikprijck
Nov 14 2016 11:58
Then when the response is back, you start the $timeout.
Roshan Bhalla
@rbhalla
Nov 14 2016 11:59
I am just concerned with what happens after the request returns
I should see repeating, time and then start, time + 2s
Frederik Prijck
@frederikprijck
Nov 14 2016 12:00
But this code is recursivly calling itself ?
Roshan Bhalla
@rbhalla
Nov 14 2016 12:00
yes
does what I'm saying make sense? It is simply a poller, and the time between the request returning, and a new request being sent should be 2s
not 10s+
Frederik Prijck
@frederikprijck
Nov 14 2016 12:01
But aren't you hitting a stackoverflow ?
Roshan Bhalla
@rbhalla
Nov 14 2016 12:01
no, this seems to be happening only 1 or 2 calls deep
Frederik Prijck
@frederikprijck
Nov 14 2016 12:02
k
Roshan Bhalla
@rbhalla
Nov 14 2016 12:02
also, there is an exit scenario, I just haven't included it to keep it clear
Frederik Prijck
@frederikprijck
Nov 14 2016 12:02
You know how Event Loops work ?
Roshan Bhalla
@rbhalla
Nov 14 2016 12:02
yes I'm familiar with them, I just don't think this case is demanding enough for javascript to be the thing throttling the recursive call
Frederik Prijck
@frederikprijck
Nov 14 2016 12:02
Even tho I wouldn't expect it to have such a great amount of impact.
Roshan Bhalla
@rbhalla
Nov 14 2016 12:03
1 or 2 recursions shouldn't be enough for anything to be strained
Frederik Prijck
@frederikprijck
Nov 14 2016 12:06
@rbhalla could you change it to:
function getResponse() {
    console.log('start', now());

    return $http({...})
        .then((x) => {
            console.log('repeating', now());
            $timeout(getResponse, 2000);
            return x;
        });
}
This aint the solution tho, but I would like to know the difference in timings ...
Or could you create a plunkr so I can have a look ?
Rakesh Chandra
@RakPavuluri_twitter
Nov 14 2016 13:26
What's the Alternative for angular.element in angular 2?
George Kalpakas
@gkalpak
Nov 14 2016 13:46
@RakPavuluri_twitter, there nothing too close to angular.element I am afraid. (You can use plain ol' jQuery of course, but I wouldn't recommend that.)
You can grad the underlying nativeElement my injector ElementRef, but directly manipulating the DOM isn't recommended either. Depending on what exactly you want to achieve, using the Renderer could be a good alternative (and is also safe in non-DOM environments as a bonus).
(In any case, this channel is for Angular 1.x :grin: You should try on the Angular 2 channel.)
Rakesh Chandra
@RakPavuluri_twitter
Nov 14 2016 13:48
@gkalpak thanks man!! Will try that out! :)
Roshan Bhalla
@rbhalla
Nov 14 2016 14:32
@frederikprijck unfortunately that stops the polling from happening at all. You have to return the result of the timeout, otherwise you won't get the result of the poll. Since this problem happens quite randomly, I'll give it a go and update here if it changes anything
Frederik Prijck
@frederikprijck
Nov 14 2016 14:33
I know that will break some things, but you're currently only interested in where the delay comes from, right ?
Once you know that, you could rebuild the functionality.
Roshan Bhalla
@rbhalla
Nov 14 2016 14:34
very true! Problem is it's so random, it's not something I can push out to users to help me gather data, so it might take a little longer to determine how it affects things
Kim Sean Pusod
@kimsean
Nov 14 2016 16:12
hello guys i have some problem

$scope.usermessage = [];
messageService.get({id: $scope.user._id},function(response){
$scope.usermessage = response.searchResult;
});
console.log($scope.usermessage);

why is it that the log is undefined ?

Frederik Prijck
@frederikprijck
Nov 14 2016 16:13
Because it's asynchronous
this code: $scope.usermessage = response.searchResult; is executed after executing console.log($scope.usermessage);
Kim Sean Pusod
@kimsean
Nov 14 2016 16:14
what should i do so i can get and insert it to usermessage ?
i've been having this problem for hours oh god
Frederik Prijck
@frederikprijck
Nov 14 2016 16:14
It will be inserted.
Just bind usermessage to the UI
and you will see the UI update when the result is ready
And if you realy want to be notified in code when it's set, add a watcher for it .
Kim Sean Pusod
@kimsean
Nov 14 2016 16:29
i checked its in ng-repeat
and there is no data
but in console there is
Sanjay Hona
@sssanjaya
Nov 14 2016 16:32
Can beginners join here?
Troy Hawley
@troywoy
Nov 14 2016 16:32
@kimsean, show us your ng-repeat template.
Kim Sean Pusod
@kimsean
Nov 14 2016 16:48
btw i got it the ng-repeat
the problem is that it loops all over even i have only 1 data to show
<tr ng-repeat="msg in usermessage">
<td><input type="checkbox"></input></td>
<td>Today, 9:18AM </td>
<td>{{usermessage.sender_id}}</td>
<td>{{usermessage.subject}}</td>
</tr>
Troy Hawley
@troywoy
Nov 14 2016 16:50
Those <td> need to be msg.sender_id and msg.subject.
Frederik Prijck
@frederikprijck
Nov 14 2016 17:49
@sssanjaya Ofcourse !
Davor Lozic
@warriorkitty
Nov 14 2016 18:29
Hi all. I have some custom code (initializing MetisMenu) which works great and I want to put it inside a Component's constructor and call it within AppComponent's directives[]. Is a Component a good place to put your custom JS code without a view? I don't want to make a decorator and a selector for this.
Ah, sorry (Angular 1 only).