从节点获取数组并填充HTML下拉菜单

时间:2016-08-19 04:59:44

标签: javascript html angularjs node.js http

所以我有一个nodejs服务器,它包含一个用户数组(每个用户都有一个名称和令牌)。在app启动时(使用离子),我想获取用户数组并填写html下拉菜单。如果被要求,我会发布所有代码。 (不发布它,因为它似乎没有必要)。

我怎样才能完全达到目的?我知道我的ionicPlatform.ready()方法中需要一个$ http.get()。但我不确切知道如何将数组从节点传递到角度从角度到html下拉菜单。

任何人都可以帮助我吗?谢谢!

.run(function($ionicPlatform, $rootScope) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
    var push = PushNotification.init({
        android: {
          senderID: "411587591993"
        },
        browser: {
            pushServiceURL: 'http://push.api.phonegap.com/v1/push'
        },
        ios: {
            alert: "true",
            badge: "true",
            sound: "true"
        },
        windows: {}
    });
      push.on('registration', function(data) {
          console.log(data.registrationId);
          $rootScope.devToken = data.registrationId;
      })
      push.on('notification', function(data) {
          if (data.additionalData.foreground) {
              alert(data.message);
          }
      })
      $scope.users = null;
      $http.get('http://192.168.1.2:8080').then(function(response) {
         $scope.users = response.data;
          console.log(users);
      });
  });
})
<body ng-app="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Push Notifications</h1>
      </ion-header-bar>
      <ion-content>
          <div class="form1" ng-controller="myCtrl">
              <form class="form">
                <input type="text" class="fName" placeholder="First Name"ng-model="fName">
                  
                <input type="text" class="lName" placeholder="Last Name"ng-model="lName">
                  
                <input type="text" class="messageText" placeholder="Message" ng-model="messageText">
                
                <select ng-model="users">
                      <option value="">Select User to Notify</option>
                </select> 
                
                <button class="button" ng-click="submit()"><span>Submit</span></button>
              </form>      
          </div>
      </ion-content>
    </ion-pane>
  </body>

0 个答案:

没有答案