謝謝!將其轉換爲我的Ionic項目並使set函數也處理回調。
page.html中
<div class="item range range-light">
<span class="smallA"><i class="ion-ios-sunny-outline"></i></span>
<input id="range" type="range" min="0" max="1000" ng-model="brightness" ng-change="setBrightness(brightness)">
<span class="bigA"><i class="ion-ios-sunny"></i></span>
</div>
controller.js
和設置的功能
$scope.setBrightness = function (newBrightness) {
myBrightness = parseFloat(newBrightness)/1000;
if (window.cordova && window.cordova.plugins.brightness) {
var LightControl = cordova.plugins.brightness;
try {
LightControl.setBrightness(myBrightness, setsuccess, seterror);
}
catch(err) {
console.log("setBrightness", err);
}
function seterror(e) {
console.log("seterror", e);
}
function setsuccess(e) {
console.log("setsuccess", e);
var brightness = Math.round(e*1000);
$scope.brightness = brightness;
}
}
}
而get函數
可能會將此移至app.js,因爲我可能會在其他控制器中需要它。
$scope.$on('$ionicView.enter', function(){
if (window.cordova && window.cordova.plugins.brightness) {
var LightControl = cordova.plugins.brightness;
try {
LightControl.getBrightness(getsuccess, geterror);
}
catch(err) {
console.log("getBrightness", err);
}
function geterror(e) {
console.log("geterror", e);
}
function getsuccess(e) {
//alert("Brightness value - " + e);
var brightness = Math.round(e*1000);
//alert("Brightness value - " + brightness);
$scope.brightness = brightness;
}
}
});
Thanks Gandhi!在Ionic下面發佈我的解決方案。 –
@彼得有同樣的彼得。如果它有幫助,你也可以upvote。 – Gandhi