3

我对使用 ionic/AngularJS 非常陌生,我想知道如何准确地使用 ionic.Platform 来打印当前设备。现在我有

var currentPlatform = ionic.Platform.platform();  

在我的 main.html 中。有没有办法将它发送到 html 页面,还是我完全错误地接近它?

4

1 回答 1

7

从您的控制器数据发送到视图使用应用程序模型 $scope,意味着只需将您的变量分配给范围变量并直接在您在视图中调用控制器的位置获取它。

例子 :

    angular.module('scopeExample', ['ionic'])
    .controller('MyController', ['$scope', function($scope) {
          var currentPlatform = ionic.Platform.platform();  
          $scope.currentPlatform = currentPlatform;
    }]);

鉴于您访问

      <body ng-app="scopeExample">
        <ion-pane>
          <ion-header-bar class="bar-stable">
            <h1 class="title">Ionic Blank Starter</h1>
          </ion-header-bar>
          <ion-content ng-controller="MyController">
           {{currentPlatform }}
          </ion-content>
        </ion-pane>
      </body>

有关更多详细信息,请参阅以下链接:

链接1 ,链接2 和链接 3等。

希望这会对你有所帮助。

于 2015-04-15T06:02:53.580 回答