Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  190] [ 4]  / answers: 1 / hits: 29397  / 9 Years ago, thu, august 13, 2015, 12:00:00

I'm quite simply trying to find out how I can retrieve the scopes information to see if it has a value or not in the controller.



I need to be able to write an if statement that says if this text input field is filled do this... if else do something different.



<form name=deadlineForm>
<div class=app-select-date>
<label for=deadline>Select deadline:</label>
<input pickadate ng-model=deadline format=dd/mm/yyyy placeholder=Select deadline/>
</div>
</form>


What is the best way about writing this code in the controller?


More From » angularjs

 Answers
9

You have it bound to a variable (deadline) using ng-model=deadline.



Your check in the controller becomes as simple as:



if ($scope.deadline != null && $scope.deadline != ) {
//do something
}


or this can be even simplified to



if ($scope.deadline) {
//do something
}


Simple JSFiddle DEMO.


[#65424] Tuesday, August 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billosvaldor

Total Points: 601
Total Questions: 113
Total Answers: 113

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;