【发布时间】:2015-02-03 11:50:22
【问题描述】:
您好,我正在使用 Ionic 框架和 Cordova 开发一个混合应用程序。我希望使用设备 uuid 作为 ID,所以我添加了 cordova 设备插件。此外,我正在使用 NG-Cordova 包装器来调用我的 cordova 插件。但是,每当我在 xcode 模拟器或实际 Ipad 上运行我的应用程序时,我得到的只是 {{uuid}} 。
似乎没有任何错误消息,我只能假设设备插件不工作。
我已将我的代码放在下面,但我不确定这是问题所在,以前有没有人遇到过这个问题,如果有,他们是如何解决的?
控制器:
angular.module('starter.controllers', []).controller('DashCtrl', function(
$scope, $state, $cordovaDevice) {
var init = function() {
console.log("initializing device");
try {
$scope.uuid = $cordovaDevice.getUUID();
} catch (err) {
console.log("Error " + err.message);
alert("error " + err.$$failure.message);
}
};
init();
})
HTML
<ion-view title="Dashboard">
<ion-content class="padding">
<h1>Dash</h1>
{{uuid}}
</ion-content>
</ion-view>
app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(
true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
}).config(function($stateProvider, $urlRouterProvider) {
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
// Each tab has its own nav history stack:
.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
controller: 'DashCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/dash');
});
【问题讨论】:
-
这是一个错字还是你真的错过了 ng-controller ??
-
我不需要 ng-controller,因为它在路由中被调用...抱歉应该说清楚
-
更新了问题以包含我的 app.js 文件
-
我没有看到您已将 ngCordova 包含到您的 angular.module 指令中。我们还缺少更多代码吗?
-
当我将 ngCordova 包含到应用程序中时,它只会出现一个空白屏幕并且不起作用......我认为这可能是我的问题的原因,如果我创建一个全新的项目并将 ngCordova 包含在我的模块一切正常。
标签: ios angularjs cordova ionic-framework cordova-plugins