$scope.$watch doesn't work as expected - angularjs

Now, I am using a check box to disable/undisable other buttons's click.
My code is here:
<button class="dateicon" ng-disabled='ExpReport.Beld' ng-click="openstart($event)">button1</button>
<button ng-disabled='ExpReport.Beld' class="dateicon" ng-click="openend($event)">button2</button>
<input id='beld' ng-model='ExpReport.Beld' class='checkboxinline' type='checkbox'/>
$scope.ExpReport.Beld = false;
$scope.$watch('ExpReport.Beld',function(){
if($scope.ExpReport.Beld=true){
$scope.ExpReport.startdate = '';
$scope.ExpReport.enddate = '';
}
})
it seems like the checkbox is always set false, when I make a breakpoint, it will set true,then turn back to false immediately. any idea?

The following line
if($scope.ExpReport.Beld=true){
is actually assignment of the $scope.ExpReport.Beld variable, not a comparison. Make sure you use double or triple equals.
if($scope.ExpReport.Beld == true){
or
if($scope.ExpReport.Beld){
will work just fine.

if($scope.ExpReport.Beld=true){
this line. If you are doing a comparison, use == or ===

Related

JSX React brackets comparing values

Can someone expalain this code to me? I am getting a (false && false && why are you comparing a hyperlink markup?
{id === constants.ACCOUNT_NO && sessionState['backBtnAddressDetails'] &&
Confirm details }
The logic that the chained &&s implement is: the final expression in the chain, that is, the
Confirm details
gets rendered only if the prior two expressions are truthy.
Another way of doing the same thing would be:
{showConfirmLink()}
const showConfirmLink = () => {
if (id !== constants.ACCOUNT_NO || !sessionState['backBtnAddressDetails']) {
return null; // don't render anything
}
return Confirm details;
};
Another example of this, outside of React:
const theValue = 'abc' && true && 'theValue';
console.log(theValue);
If any of the expressions in an && chain are falsey, the chain stops evaluating there, and the whole thing resolves to that falsey expression. Otherwise, it evaluates to the final expression in the chain.
This type of expression is referred to as conditional rendering in React ,
basically if the condition is true, the element right (the Confirm details element in your case ) after && will appear in the output. If it is false, React will ignore and skip it.
it could mean the id and constants.ACCOUNT_NO aren't of the same type (when you use the === operator it strictly compares the types too )
another possibility is sessionState['backBtnAddressDetails'] could be null

Why adding string make my condition not working

I am using reactJS and I am using some conditions to show my components. The code below is properly working. It show my success message without any problem. The FINALMESSAGE.showFinalMessage = true and FORMSTATUS["loadingForm"] = false
{FINALMESSAGE.showFinalMessage && !FORMSTATUS["loadingForm"] && <FinalMessageSave></FinalMessageSave>}
But when I add a condition with string like this:
{FINALMESSAGE.showFinalMessage && FINALMESSAGE.finalMessageStatus === "SUCCESS" && !FORMSTATUS["loadingForm"] && <FinalMessageSave ></FinalMessageSave>}
it doesnt work anymore even the FINALMESSAGE.showFinalMessage = "SUCCESS"
Here is the screenshot of my state

my conditional returns undefined instead of true/false

I'm using angularjs and trying to set up a flag on the front end for my ng-if. I wanted to consolidate the logic in the controller but the the ng-if is only returning true and never false.
I need some efficient way for my code to return false if conditions are not met instead of returning undefined.
vm.showLocButton = !vm.isSupervisorReviewApp && vm.application.benefitPeriod.program.programType.id === vm.constants.programTypeId.directBill && vm.application.applicationStatus.code === vm.constants.applicationStatus.locIssued;
Dont know exactly but I see '=' instead of '==' are you assigninv the value or comparing if comparing than try using '=='
vm.showLocButton == !vm.isSupervisorReviewApp && vm.application.benefitPeriod.program.programType.id === vm.constants.programTypeId.directBill && vm.application.applicationStatus.code === vm.constants.applicationStatus.locIssued;
It will really helpful if you can post the entire code.

AngularJS issue showing dynamic phrases according to a scope value.

I have an issue. When people click on a link, this variable add 5 to the original value:
$scope.sumareco = function(cantidad) { $scope.contadoreco += cantidad};
If i print the value {{sumareco}} you can see how the value changes.
The problem starts when I create a conditional on the controller.
if ($scope.contadoreco < 30 && $scope.contadoreco > 10) {
$scope.resultadoeco = "Opción uno";
} else {
$scope.resultadoeco = "";
}
If I print {{resultadoeco}} I expect that the phrase changes dinamically depending of the numeric value of $contadoreco. But it remains static and only shows the phrase assigned to the original value. ¿What can I do?
Thanks
I'm guessing your if statement is just sitting in your controller and not inside any method or statement that would run during a digest cycle.
The easiest way to update resultadoeco is to watch contadoreco. For example
$scope.$watch('contadoreco', function(val) {
$scope.resultadoeco = val > 10 && val < 30 ?
'Opción uno' : '';
});
See https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watch

Cakephp - how check row is null?

I want to set flash message if there's not fullfilled row "surname" in database. How can I check if row surname is null ?
I tried to make something like this:
if(!isset(['User']['surname'])
or
if($user(['User']['surname']) === NULL
it obviously doesnt work
You can check it like.
<?php
if(!isset($user['User']['surname']) || empty($user['User']['surename'])){
// your code goes here
}
if(empty($user['User']['surname'])) {
// your code goes here
}
you can check like this
if(isset($user['surname']) || empty($user['surname'])){
$this->Session->setFlash('No Data.');
}

Resources