Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a cart controller, that manages cart in e-store. Ordered products are stored in scope.cart. In view I have buttons to change item's cnt, like <elem ng-click="inc(c)" />, so inc function incrementing c.cnt
Now, I want to watch cart object, so on cnt change I can make XHR call to change data in user session. That's ok and working fine, the problem is I have some difficult pricing rules, so I have to return prices manually within same XHR query, and update scope.cart. This makes a loop, and I wonder how do I make things proper, angular-way?
You don't have to watch the cart object changes if you have a function that increments the cart items.
i.e
$scope.inc = function(c) {
// Do your cart logic here and then
$http({method: "PUT", url: "/cart"})
.success(function(data, status, headers, config) {
// update cart object with new pricing rules
})
.error(function(data, status, headers, config) {
// handle errors
});
};
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
Lets say I have two structs in a swiftui file. How do I declare a bool variable (that is false by default) and let it get access to all structs like a public variable. I need this because in my case is a button changing the value of this variable in another struct, but it can't because it doesn't work with #state or #binding. I get this error when using #Binding var varName = false "No exact matches in call to initializer". I just need a variable that can be changed its value from other structs. I already tried it with a class and an observable object but this didn't work either.
You can have an state in your content view. There you can observe that state variable to see if the user is logged in or not.
If is logged in, you navigate to the main screen. If not, you just go to the login screen. That way you define the navigation the app should take.
Be aware that you need to pass that state variable to the login screen in order to be able to change its value, so the content view can react to that change.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a OData Model in my application, where I want to add a new entry.
This code works fine in my case:
ODataModel.createEntry("/showcaseSet", {
properties: {
"property": "Haris"
}
});
But when I am doing the same with array it doesnt work:
var oEntry = [];
oEntry.push(
{
"property": "Haris"
}
);
ODataModel.createEntry("/showcaseSet", oEntry);
When I am submitting the chages from the Model to my backend, I don't recieving any data from the frontend. Only when I am working in the first case or code i described.
Do you know where my problem is?
In v2.ODataModel, the createEntry API is expecting just an object in the second argument, not an array.
In that case, you could do something like this:
oEntry.forEach(e => ODataModel.createEntry("/showcaseSet", e));
// binding against this entity
oForm.setBindingContext(oContext);
// submit the changes (creates entity at the backend)
oModel.submitChanges({success: mySuccessHandler, error: myErrorHandler});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to reset the state of this statement:
[[IAPManager sharedInstance]isProductPurchased:kInAppItem] = FALSE;
However, i'm getting the error of "Assigning to 'readonly' return result of an Objective-C message not allowed". How do i reset the state of this statement?
In IAPManager.m
-(BOOL)isProductPurchased:(NSString *)productIdentifier
{
return [_purchasedProducts containsObject:productIdentifier];
}
Your left hand side is a method invocation that returns a BOOL, it is not a reference to the property itself, so you cannot assign a value.
You need to refer to the code for IAPPurchase, but if it this library then there is no method to reset the purchased state for a product.
You can delete the app or delete the plist the library uses to store purchase data (by the way, this isn't a very secure way of recording in-app purchases)
You can't assign a value to a return value of a method in Objective-C. You may be confused by the syntax
myObject.myProperty = myValue;
This sets the value of myProperty to myValue, but in doing so it essentially calls this method:
[myObject setMyProperty:myValue];
Either way, the left side of your code will be handled as a return value, not a property. Therefore you can't assign it.
If there exists a method like setProductPurchased: or setIsProductPurchased:, you need to call that like the second example. Otherwise there isn't a way to set the property, so you may have to set an instance variable directly.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Lets consider the string "My name is #{#user.name}"
So i need to check and handle the error in this part "#{#user.name}".
Error may be because of "#{user.name}" (user object is undefined) or "#{other_object.name}"
or accessing the attribute that does not belong to the user table.
You can use:
name = "#{object.name}" if object.respond_to?(:name)
If object doesn't respond to #name method (it also handles the case when object is nil), nil will be assigned to name variable.
Try this
"My name is #{#user.try(:name)}"
TRY method will return nil if it caught exception, it wont throw any error.
Simple error handling
begin
string = "My name is {#user.name}"
rescue
string = "My name is not currently available"
end
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am developing an app with a shopping cart. When I add a product, I have to check if this product exist. I was using this method:
for (go over all products){
if(product exists){
--only change the quantity of the product[n]
}
else{
--create a new product object with all its properties
}
}
But with this method if the product I want to add don´t is the same with the index 0 (the first that the for checks), always add a new object (product) so if for example, my product exists and have the index 2, this for never will know that it exists.
Sorry for my english ;) and thank you.
If I understood it right, you're problem is, that you loop over all the products and if the product is not the same as the new one, you just add a new one.
but you'll need to loop over all entries first and after you have done that and didn't find anything, you create a new product.
So in pseudo code:
bool productExists = false;
for every product {
if(same product) {
productExists = true
change the quantity
break;
}
}
if(!productExists) {
add new product
}