4

my code my controller:

App.controller('TestCtrl', function ($scope, $http) {
   console.log("CTRL STARTED");

   if (angular.isDefined($scope.test)) <--------------- ERROR
      {
         alert('UNDEFINITA');
         LoadDefault();
      };

My HTML

 <select class="form-control" ng-options="people.id as people.name for people in      peoples" ng-model="test" ng-change="LoadAnotherSelect()">
    <option value="">Seleziona azienda...</option>
 </select>

How to know if test variable is undefined???? Thank's in advanced

1 Answer 1

5

your code seems fine, what error are you getting?

as you can see, this code works, using angular.isDefined($scope.name):

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  if (angular.isDefined($scope.name)) {
    alert($scope.name);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
  </body>

</html>

Sign up to request clarification or add additional context in comments.

6 Comments

Hi Nitsan, if get error "undefined is not a function...Thanks.
@Aesis are you sure the error comes from isDefined? what version of angular?
Yes, Angular 1.2.26 Error: TypeError: undefined is not a function
@Aesis as you see in the answer, the code runs fine. your error comes from elsewhere. please post a plnkr/fiddle and reproduce the error
jsfiddle.net/y3zvxm4g this is my code! The error is when call "caricaAziende()" from if. Why? Thank's
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.