离子设置使用指南
Guidance with ionic-settings usage
我正在尝试配置我的应用程序以使用 ionic-settings 代码。
我的问题是关于 "Usage" 部分的。
将第 4 项中列出的代码放在哪里?
请参阅下一节 (#5)
// INITIALIZATION IN CONFIG PHASE (USING PIN)
angular.module('starter', ['ionic', 'ionicSettings'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('main', {
url: '/main',
abstract: true,
templateUrl: 'templates/main.html',
resolve: {
settings: function($ionicSettings, $ionicPopup) {
var settings = {
toggle1: {
type: 'toggle',
label: 'Toggle 1',
value: true
},
toggle2: {
type: 'toggle',
label: 'Toggle 2',
value: false
},
pin: {
type: 'pin',
label: 'PIN',
value: '',
onValid: function() {
$ionicPopup.alert({
title: 'Success',
template: 'Welcome!'
});
},
onInvalid: function($event, wrongPinValue) {
$ionicPopup.alert({
title: 'Fail',
template: 'Wrong pin: ' + wrongPinValue + '! Try again.'
});
}
}
};
return $ionicSettings.init(settings);
}
}
})
});
// INITIALIZATION IN CONTROLLER (WITHOUT PIN)
angular.module('starter.controllers', [])
.controller('YourCtrl', function($scope, $ionicSettings) {
$ionicSettings.init({
awesomeSelection: {
type: 'selection',
values: ['one', 'two', 'three'],
label: 'Awesome Selection',
value: 'two'
},
coolToggle: {
type: 'toggle',
label: 'Cool toggle',
value: true
}
});
});
我正在尝试配置我的应用程序以使用 ionic-settings 代码。
我的问题是关于 "Usage" 部分的。 将第 4 项中列出的代码放在哪里?
请参阅下一节 (#5)
// INITIALIZATION IN CONFIG PHASE (USING PIN)
angular.module('starter', ['ionic', 'ionicSettings'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('main', {
url: '/main',
abstract: true,
templateUrl: 'templates/main.html',
resolve: {
settings: function($ionicSettings, $ionicPopup) {
var settings = {
toggle1: {
type: 'toggle',
label: 'Toggle 1',
value: true
},
toggle2: {
type: 'toggle',
label: 'Toggle 2',
value: false
},
pin: {
type: 'pin',
label: 'PIN',
value: '',
onValid: function() {
$ionicPopup.alert({
title: 'Success',
template: 'Welcome!'
});
},
onInvalid: function($event, wrongPinValue) {
$ionicPopup.alert({
title: 'Fail',
template: 'Wrong pin: ' + wrongPinValue + '! Try again.'
});
}
}
};
return $ionicSettings.init(settings);
}
}
})
});
// INITIALIZATION IN CONTROLLER (WITHOUT PIN)
angular.module('starter.controllers', [])
.controller('YourCtrl', function($scope, $ionicSettings) {
$ionicSettings.init({
awesomeSelection: {
type: 'selection',
values: ['one', 'two', 'three'],
label: 'Awesome Selection',
value: 'two'
},
coolToggle: {
type: 'toggle',
label: 'Cool toggle',
value: true
}
});
});