lundi 23 mars 2015

Where do you put page-specific scripts in Ionic?


I am making an app with ionic and I have JS scripts for each page. For example, one page has a script that will change the message based on time of day, while another page has a jQuery .load() script. Neither seems to be working. They are DOM-manipulative, and are at the bottom of the page.



<ion-view view-title="Welcome" style="text-align:center; padding:20px;">
<ion-content>
<h1 id="time">Hello!</h1>
<p>Welcome to the app. We are thrilled to share our new app with you!</p>
</ion-content>
<script>
date = new Date();
var hours = date.getHours();
console.log(hours);
if (hours >= 5 && hours <= 11) //MESSAGE FOR MORNING
document.getElementById('time').innerHTML = 'Good Morning.';
else if (hours >= 12 && hours <= 17) //MESSAGE FOR AFTERNOON
document.getElementById('time').innerHTML = 'Good Afternoon.';
else if (hours >= 18 && hours <= 20) //MESSAGE FOR EVENING (6pm-8pm)
document.getElementById('time').innerHTML = 'Good Evening.';
else //MESSAGE FOR NIGHT (9pm-4am)
document.getElementById('time').innerHTML = 'Good Night.';</script>
</ion-view>


Controllers.js:



angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
// Form data for the login modal
$scope.loginData = {};

// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});

// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.modal.hide();
};

// Open the login modal
$scope.login = function() {
$scope.modal.show();
};

// Perform the login action when the user submits the login form
$scope.doLogin = function() {
console.log('Doing login', $scope.loginData);

// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() {
$scope.closeLogin();
}, 1000);
};
})

.controller('PlaylistsCtrl', function($scope) {
$scope.playlists = [
{ title: 'Reggae', id: 1 },
{ title: 'Chill', id: 2 },
{ title: 'Dubstep', id: 3 },
{ title: 'Indie', id: 4 },
{ title: 'Rap', id: 5 },
{ title: 'Cowbell', id: 6 }
];
})

.controller('PlaylistCtrl', function($scope, $stateParams) {
});




Aucun commentaire:

Enregistrer un commentaire