When i add parameter using $location in url as shown below it first removes added data but i want to keep that previous data...
Example with code
Main url:
http://localhost/angular_laravel/angjs/#/bag_list
when i do this,
$location.path('/bag_list').search({category: cat_search});
it simply changes url to this,
http://localhost/angular_laravel/angjs/#/bag_list?category=1
now when next function doing something like this,
$location.path('/bag_list').search({model: model_search});
and then url changes to this,
http://localhost/angular_laravel/angjs/#/bag_list?model=1
but i want to keep both like this,
I WANT LIKE THIS:
http://localhost/angular_laravel/angjs/#/bag_list?model=1&category=1
My problem is that it deletes previous parameter but i want to keep that parameter,
any help...??
You have 2 options I believe.
If you are only setting a single value (as you are in the example) you can use the 2 argument form of the setter. eg.
$location.search('model', model_search);
If you need to set more than 1 (or your data is coming in as an object already) you can manually merge the values. eg.
$location.search(angular.extend({}, $location.search(), { model: model_search }));
Try:
$location.path('/bag_list').search({category: cat_search, model: model_search});
Related
I have a popup dialog box that I wish to display one of two slightly different views, dependant on whether I have data present or not.
Is there a way in which I can optionally pass in said data within the directives?
ie. I would like to use something like
<my-comp *ngIf="ifPopup" [data]="myData" [isNew]="isNew"></my-comp>
where the [data] may not always be present, ie. It may either be undefined or have actual data present.
I just want to avoid having to basically duplicate my component.
Update after confusion around my question
Basically I am adding a new record to my DB (imagine adding a new customer etc). My component will either be used to edit a record or create a new record. If I am editing a record, myData will be filled with this record. If I am creating a new record, myData will be undefined..
why don't you just use
<my-comp *ngIf="ifPopup && myData" [data]="myData"></my-comp>
in this way, If the myData is not present, your popup wont display
Or you can also use <ng-container> and wrap your component inside and and use ngIf for your data!
I have an anchor link where the data-url has a value of a yii create url like this
CLICK ME
so the situation is like this, you see the data-chosen-type="" attribute?, the value is actually being set by a javascript. Now what I want to happen is, grab the value of data-chosen-type attribute and place it to 'var3' value, within the array inside that createUrl thing. So the output should be like this
CLICK ME
is that possible to do?
I tried doing this
'var3' => "js:$('#download-button').attr('data-chosen-type')"
it didn't work, but in a view file especially in CGridView, putting javascript in a value of a key pair does work...how come in createUrl I wasn't able to do the same thing? am I doing it wrongly?
No, that is not possible, because PHP is long done before anything JavaScripty happens on the client.
If you can not determine the value on the server-side at all - then make an AJAX request to the server, so that you can call the createUrl method there with the correct parameters, and then set the link data-url attribute with the returned URL.
I need to use partialUpdateObject from the Algolia Javascript SDK to delete an attribute from an object that is already in the index.
My scenario is that I have a description field on my object that is optional. If the user originally sets a description and then later deletes it, I want to remove the description altogether from the object.
I do not want to overwrite the whole object (without the description attribute) because I have some count attributes on the object that I do not want to have to recalculate.
As far as I can tell in the documentation there isn't a way to do it and my workaround is to set the description as an empty string. Is that the recommended approach?
You're right: you cannot totally remove the attribute from an object with a partialUpdateObject operation. As a work-around you can set it to null, maybe that's enough for your use-case?
If you really want to delete the field you can :
Get your object with the search function
Store all fields values
Update (not partial update) your object without passing the field you want to delete
I have a collection, I can do this successfully ('this' is the collection instance):
this.on('change:username', function(model,property,something){
// model is backbone model that changed
// property is the property that changed (username in this case)
// something is some empty mystery object that I can't identify
}
however what I want to do is this:
this.on('change', function(model,property,something){
// model is backbone model that changed
// ***how can I read the properties that changed here?***
// something is some empty mystery object that I can't identify
}
the problem is that in the second case, I can't get the property that changed...maybe that's because it's potentially multiple property changes all at once.
How can I capture that properties that changed in the second case? is this possible?
The only way I know how to do this would be
this.on('change', function(model, something){
// something object is unidentifiable
var changed = model.changed; //hash of changed attributes
}
so my other question is: what is that mystery object "something"? It is just an empty object...?
You have a couple of options you can use in general change events:
Backbone.Model#hasChanged: This will allow you to see if a model attribute has changed in the context of this change event. If so, you can get its new value and apply it to the view (or whatever other context) as needed.
Backbone.Model#changedAttributes: This will allow you to get all changed attributes since the last set() call. When called with no parameters, it is a defensively cloned copy of the changed hash; you can also pass in a hash of parameters and get only what is different about the model relative to that set of key/value pairs.
Backbone.Model#previous: This will allow you to get the previous value of a model attribute during a change event.
Backbone.Model#previousAttributes: This will allow you to get all the previous values of a model during a change event. You could use this to completely undo a change (by calling set with the result of this function) if you wanted to.
By the way, the third parameter of the change:attr event (and the second of change) is an options object, which can be useful if you want to specify custom values that can be read by your event handlers. There are also a number of standard options Backbone will handle specially. See the documentation for Backbone.Model#set for more information on the specific options, and take a look at the Backbone event list to see the callback signatures expected when those events are triggered.
I have an <input ng-model='list' ng-list>, and I want to make sure that no duplicates appear in this text field—I want to automatically remove them if the list contains duplicates.
I put a $scope.$watch('list', function(listValues) { in the controller, and try to remove any duplicates from listValues, but have problems. From within the watch function, if I set listValues = _.unique(listValues), $scope.list's value never changes. If I try $scope.list = _.unique(listValues), I get an error about the digest cycle already running.
How can I watch for a scope variable to change, and when it does, perform an operation to change that new value?
Here's an example of it not working: http://plnkr.co/edit/b0bAuP1aXPg3HryxCD9k?p=preview
I thought this would be simple. Is there some other approach that I should be using?
ng-change is probably a better approach in this case. In particular, this attribute of ng-change:
if the model is changed programmatically and not by a change to the
input value
If you place your de-dupe in a function and then use ng-change to call it, I think you will get the results you are after.