Angularjs test if scope variable is undefined or null -


my code 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 people.name people in      peoples" ng-model="test" ng-change="loadanotherselect()">     <option value="">seleziona azienda...</option>  </select> 

how know if test variable undefined???? thank's in advanced

your code seems fine, error getting?

as can see, 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>


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -