These are chat archives for angular/angular.js

15th
Apr 2015
Pravin
@codefullon
Apr 15 2015 03:29
hi all, how can I set my ng-model value dynamically?
tried this (and similar variations)syntax and it does not work:
ng-model="keywordTags+$index+1"
Wesley Cho
@wesleycho
Apr 15 2015 04:16
@codefullon you would have to create a directive wrapper that dynamically $compiles the html with the dynamic ng-model attribute value
Pravin
@codefullon
Apr 15 2015 04:49
excellent, thanks @wesleycho trying that now
Pravin
@codefullon
Apr 15 2015 05:24
one more :-) want to assign an empty array for the dynamically created model in the element, tried the following but it does not work:
ng-init="keywordsTags + {{$index+1}}=[];"
 <tags-input ng-class="useKeywordTags{{$index + 1}}" ng-init="keywordsTags + {{$index+1}}=[];" ng-model="$parent['keywordTags' + ($index + 1)]">
</tags-input>
above is the entire code for this element; this element is within a ng-repeat statement and then creation of dynamic model names is working well this way although the ng-init bit is not and as per the directive, I need to create an empty array for each of the models in order to have the tags inside the input field working
Wesley Cho
@wesleycho
Apr 15 2015 12:35
use a callback with ng-class that passes in $index as the argument and returns the class string you want
or use the regular class attribute
Pravin
@codefullon
Apr 15 2015 13:15
thanks @wesleycho :-)
app.filter('onlypath', function() {
 return function(input, delimiter) {
    input = input || ','
    delimiter = delimiter || ','
    return input.split(delimiter);
  }
});
applying the 'onlypath' filter to a ng-repeat statement although i get TypeError: undefined is not a function, any idea where i'm going wrong?
searched on stackoverflow but the comments usually say that the parameters should be defined then it works fine eg: input = input || ','
but that does not seem to be solving it
Pravin
@codefullon
Apr 15 2015 13:22
oh wait, its perhaps because i'm iterating over an object and not a string per se
time to google a little more :-)
Pravin
@codefullon
Apr 15 2015 13:30
awesome solved it, silly mistake, was using the filter on the whole object instead of that particular element where the computation was supposed to happen
Mike Haas
@mikehaas763
Apr 15 2015 13:42
In my httpbackend I mock a get that responds with an array. If within my test I push a new element onto that array shouldn't successive requests that get that array back have the new element in it being that it should be a reference to the original array?
Darrin Dickey
@darrindickey
Apr 15 2015 15:53
@gautelo, @timjacobi Update on my custom filter. The reason it wouldn’t pick up “items” from the ng-repeat was that the filter was running before the data reached it.
I used:
if !items or !items.length
return
which makes sure the data is there before the filter runs. Now it works. Thanks.
Gaute Løken
@gautelo
Apr 15 2015 16:52
@darrindickey It should still update later when the data arrives. If it doesn't that's indicative of you not telling angular that something happened. In short, if you do a native XHR or use jquery.ajax or something, you need to call $scope.$apply in order for angular to do a new digest, meaning dirtycheckig watches, expressions etc. Instead of doing that however, I would suggest using the $http service, which will trigger the digest for you.
Darrin Dickey
@darrindickey
Apr 15 2015 16:58
@gautelo Does the fact that the data I’m bringing in from the API is being retrieved in a Service using ngResource instead of $http have an impact on that?
Gaute Løken
@gautelo
Apr 15 2015 17:03
@darrindickey No, $resource should also trigger digest for you. What I said only holds for things that weren't made for angular. So it appears I'm wrong. Why adding an ng-if on it would help you, I don't know. Unless you have a one-time-binding on your repeater. Anyway.. if it's working, it's working. ;)
Ahh.. you're saying that your filter was crashing due to an exception, and by adding some contingencies to the actual filter code, you fixed the issue!
Darrin Dickey
@darrindickey
Apr 15 2015 17:05
Who knows. There’s still so much for me to learn about this. :-)
Gaute Løken
@gautelo
Apr 15 2015 17:05
I wrongly interpreted your snippet as pseudocode for the html.. :)
Darrin Dickey
@darrindickey
Apr 15 2015 17:05
Thanks again!
Gaute Løken
@gautelo
Apr 15 2015 17:05
Most welcome
Jon Stevens
@lookfirst
Apr 15 2015 21:08
Dear interwebs… Best (smallest, simplist) loading screen (just need to black out the window until an ajax request completes) library for angular.js 1.3.x. Go!
Neel
@neelneelneel
Apr 15 2015 21:26

@lookfirst No need for an additional library

<div ng-if="loadScreen" class="background">
    <img class="spin" src="spin.png">
    <h3>Loading...</h3>
</div>

css

.background{
    background:black;
    opacity:.70;
    z-index:10000;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
}
.spin{
    -webkit-animation: spin linear infinite 900ms;
    -moz-animation: spin linear infinite 900ms;
    animation: spin linear infinite 900ms;
}

js
(start of call)

$scope.loadScreen = true;

(end of call)

$scope.loadScreen = false;