javascript - Return object from AngularJS $scope ng-model -
i use angularjs framework, created form.html , controller.js variable retrieves ssid of box. how automatically assign value of variable in form. input field. when launching application, form should display ssid automatically without user needing so.
$scope.ssid {}; return [object oject] in input form ng-model="ssid"
thank kindly me.
controller.js
/*controller*/ 'use strict'; angular.module('djoro.controllers') .controller('wifismartconfigctrl', function($scope, $window, $ionicplatform) {a $scope.ssid = {}; $scope.getssid = function() { var onsuccess = function(ssid) { $scope.ssid = ssid; return ssid; }; var onfail = function() {}; $ionicplatform.ready(function() { $window.cordova.plugins.smartconfig.getssid(onsuccess, onfail, $scope.ssid); }); }; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script> <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">ionic blank starter</h1> </ion-header-bar> <ion-content ng-controller="wifismartconfigctrl"> <form novalidate class="simple-form"> <fieldset> <legend>wi-fi</legend> <div class="list input-fields"> <label class="item item-input"> <span class="input-label">ssid :</span> <input type="text" name="test" ng-model="ssid" id="ssid" placeholder="ssid" required show-hide-input> </label> <label class="item item-input" show-hide-container> <span class="input-label">password :</span> <input type="passwprd" name="test" placeholder="password" required show-hide-input> </label> </div> </fieldset> </form> </ion-content> </ion-pane>
you have defined function on scope getting ssid never call ui. if want ui automatically have need call in controller initialization.
your code controller this:
.controller('wifismartconfigctrl', function($scope, $window, $ionicplatform) {a $scope.ssid = {}; var onsuccess = function(ssid) { $scope.ssid = ssid; return ssid; }; $ionicplatform.ready(function() { $window.cordova.plugins.smartconfig .getssid(onsuccess, angular.noop, $scope.ssid); }); });
Comments
Post a Comment