These are chat archives for angular/angular.js

10th
May 2018
Ghost
@ghost~5af337a1d73408ce4f98b8a9
May 10 2018 01:06
Hello . If i use jquery with wordpress , the performance of the site comes down?
riot
@ri0t
May 10 2018 13:00
hello. is there a way to have $log in every component without having to inject it all the time? I currently use console.log() but that is just.. gaaah - no loglevels etc
Tom McKearney
@tommck
May 10 2018 15:41
Anyone have any ideas why a call to isolateScope() on my element in a unit test would return undefined after upgrading to 1.6.10?
I've been googling for about an hour and nothing applies to my situation
my code's not doing replace: true. It's a directive, not a component, so no $onInit issues or anything
Tom McKearney
@tommck
May 10 2018 16:11
wow.. I guess the whole world moved to Angular :) This room is dead. It used to have a lot of activity
Frederik Prijck
@frederikprijck
May 10 2018 18:17

I guess you should rephrase it as the element has no ng-isolate-scope: In what circumstances could a $compile call not result in an isolated scope, even if the directive that's being compiled has scope: {}.

As the directive has no isolated scope, it's expected behavior that isolateScope() returns undefined.

@gkalpak :point_up: Any idea ?
Tom McKearney
@tommck
May 10 2018 19:07
@gkalpak @frederikprijck somehow, a missing FILTER is what caused this to happen. The template had {{ vm.foo | unrecognizedFilterName }} in it and this caused the isolateScope() to be undefined. If I have time, I'll try to reproduce it in a plunk... but it looks like it's easy to reproduce
Frederik Prijck
@frederikprijck
May 10 2018 19:22
But a missing filter throws:
Error: [$injector:unpr] Unknown provider: fooFilterProvider <- fooFilter
https://errors.angularjs.org/1.6.10/$injector/unpr?p0=fooFilterProvider%20%3C-%20fooFilter
Bryan
@bmallen1
May 10 2018 19:24
i'm trying to get a directive to update the parent scope's value depending on if a condition is met, but my lack of understanding is preventing it from working correctly
basically i'm pre-populating a form with a value that doesn't exist in the dropdown. when that happens the scope property should be updated to null
Tom McKearney
@tommck
May 10 2018 19:25
it didn't throw :)
$provide.value('unrecognizedFilterNameFilter', ....) fixed it
Frederik Prijck
@frederikprijck
May 10 2018 19:26
@bmallen1 Wow that code looks fishy.
case "$ctrl.lead.GradYear":
Bryan
@bmallen1
May 10 2018 19:27
there's room for improvement without a doubt
Frederik Prijck
@frederikprijck
May 10 2018 19:27
That's realy not something you want to be doing.
If u want acces to ngModel, you use: require: 'ngModel'.
Regarding your question: I'm not realy understanding what you want to update in the parent $scope.
Bryan
@bmallen1
May 10 2018 19:37
basically, line 42 of the plnkr
Frederik Prijck
@frederikprijck
May 10 2018 19:38
Ah the TODO ?
So you don't realy have anything which U'd expect to be updating the scope ?
Bryan
@bmallen1
May 10 2018 19:38
yes the TODO
my app is initializing with an object that it gets from somewhere
sometimes that object has properties where the values don't exist
in my plnkr i'm trying to prepop a dropdown, BestTimeToContact with a value of ","
instead of a value like Anytime,Morning,Afternoon,Evening, which are the only valid values
Frederik Prijck
@frederikprijck
May 10 2018 19:40
Well, I guess u wanna remove the hardcoded option elements in ur html, unstead bind ur select to an array of options defined in ur controller.
Bryan
@bmallen1
May 10 2018 19:40
i want the directive to update the scope property when that happens
Frederik Prijck
@frederikprijck
May 10 2018 19:40
But pretty much everything in that plunkr is discouraged from doing the way you're doing.
I don't think theres a way to just fix what you're asking in a way that makes everything works as expected without rewriting most of it.
And even if there is, you shouldn't.
Bryan
@bmallen1
May 10 2018 19:42
i shouldn't have the directive update the scope property?
Frederik Prijck
@frederikprijck
May 10 2018 19:44
What I'd do:
  • Remove the hardcoded html options, move the select options to an array and bind it to the html
  • add a directive with an input of "items" and pass it that array
  • require ngModel in that directive
  • do your logic and push the "," (or whatever value) into the items array
This also removed the need for case "$ctrl.lead.GradYear":, which you realy shoudn't use!
Bryan
@bmallen1
May 10 2018 19:45
yeah i expect the entire switch statement can be replaced, i agree with you there
it was a bandaid solution because i had two particular drop downs with different ranges of integer values and i was handling their case explicitly
all other dropdowns had string values, Yes/No, AnyTime/Morning/Evening, etc
Frederik Prijck
@frederikprijck
May 10 2018 19:47
Not sure what you mean
There no situation where u need something like this
Bryan
@bmallen1
May 10 2018 19:52
changing the html template isn't an option
the directive needs to be able to retrieve all the options for a given field and determine if it's ngModel value is in that list
Frederik Prijck
@frederikprijck
May 10 2018 19:52
It's neccesary.
U cant have a static list, and add something to a static list
Bryan
@bmallen1
May 10 2018 19:53
i don't want to add anything to a static list
the static list is static
the data that the app is initialized with could be complete shit, i don't have control over that
Frederik Prijck
@frederikprijck
May 10 2018 19:54
How's the list static, if u wanna add "," ?
Bryan
@bmallen1
May 10 2018 19:54
i don't want to add "," to the dropdown. i want to prevent it from being selected at all
Frederik Prijck
@frederikprijck
May 10 2018 19:55
Okay, so what do u want to replace the "," with ?
Bryan
@bmallen1
May 10 2018 19:55
right now if i pre-pop the field with a model property of ",", which doesn't exist in the dropdown, angular adds <option value="? string:, ?" selected="selected"></option>
the ngModel should be set to NULL
if the value is null, then this will be selected <option value="">Please Select</option>
and then the form validation will take over
I created a new directive, I didn't modify yours.
You could easily replace "items" with a function with returns the items by querying the dom, if u wanna keep the list as hardcoded options in ur html. But for the rest, you shouldn't have any need for all the complexity like your directive has.
Bryan
@bmallen1
May 10 2018 20:17
did you save it? not seeing the update
Frederik Prijck
@frederikprijck
May 10 2018 20:17
Hold on
Frederik Prijck
@frederikprijck
May 10 2018 20:26
I also added a version which keeps the options in html.
Frederik Prijck
@frederikprijck
May 10 2018 20:32
Note: AngularJS still adds the "? string:, ?" option.
Bryan
@bmallen1
May 10 2018 20:32
thank you @frederikprijck, that's awesome. pretty much exactly what i was after
Frederik Prijck
@frederikprijck
May 10 2018 20:33
Try to get rid of ur directive and replace it with the one I gave u. Lot more flexible.
This will work for any select u every use :)
Aslong as it uses strings that is.
If u work with objects, u might need to rework it a bit
However, I'm still researching whether there's an even simpler option.
Bryan
@bmallen1
May 10 2018 20:36
yes i will definitely be replacing mine with one of yours
to give some background: the app i'm usually working on is a call center application
the call center agents launch my app from their shitty dialer software, which pre-pops shit sometimes, and i use that data to pre-populate a dynamic form.
each call center asks the same questions, but sometimes in a different order, or sometimes they need a drop down list to not have certain options. Currently, this is most easily managed by having static templates defined
at any rate, thanks so much for your help
Frederik Prijck
@frederikprijck
May 10 2018 20:42
I'd propably still bind the options to an array on the controller and do the pre-pop validation prior to setting the ng-model value.
This avoids any hacky approach (as we're doing) and keeps the data valid.
Coz you basicly have data coming from somewhere to your application, which u wanna "validate". That's not something that belongs in the "form", but could be easily done outside of the form as some kind of "business logic".
You're welcome @bmallen1 :)