I am using MobileFirst v8 and Ionic v1.3.1 to build an app. When the app starts I have the regular ionic angular code in my
app.js
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
...
})
.controller('IndexCtrl', function($scope, $state) {
RememberMeService.checkIfLoggedIn().success(function(data) {
alert("YAY!!");
}).error(function(data) {
alert('fail :(');
});
});
function wlCommonInit() {
var serverUrl = WL.App.getServerUrl(function(success){
console.log(success);
}, function(fail){
console.log(fail);
});
WLAuthorizationManager.obtainAccessToken().then(
function (accessToken) {
console.log(">> Success - Connected to MobileFirst Server");
},
function (error) {
console.log(">> Failed to connect to MobileFirst Server");
console.log(error);
}
);
.service('RememberMeService', function($q) {
return {
checkIfLoggedIn: function() {
var deferred = $q.defer();
var promise = deferred.promise;
var securityCheckName = 'UserLogin';
WLAuthorizationManager.obtainAccessToken(securityCheckName).then(
function (accessToken) {
console.log('USER IS LOGGED IN!!!');
},
function (response) {
console.log("obtainAccessToken onFailure: " + JSON.stringify(response));
}
);
promise.success = function(fn) {
promise.then(fn);
return promise;
}
promise.error = function(fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
}
})
WLAuthorizationManager.obtainAccessToken(securityCheckName).then
WLAuthorizationManager
wlCommonInit()
app.js
wlCommonInit()
WLAuthorizationManager
function wlCommonInit() {
function wlCommonInit() {
var serverUrl = WL.App.getServerUrl(function(success){
console.log(success);
}, function(fail){
console.log(fail);
});
WLAuthorizationManager.obtainAccessToken().then(
function (accessToken) {
console.log(">> Success - Connected to MobileFirst Server");
angular.bootstrap(document.getElementById('indexBody'), ['app']);
},
function (error) {
console.log(">> Failed to connect to MobileFirst Server");
console.log(error);
}
);
<body id="indexBody">
<h1>test</h1>
</body>
kError in Success callbackId: WLAuthorizationManagerPlugin887134242 : Error: [$injector:modulerr] Failed to instantiate module ng due to:
TypeError: Cannot set property 'aHrefSanitizationWhitelist' of null
You can bootstrap manually your angular App in wlCommonInit
success callback. See https://docs.angularjs.org/guide/bootstrap#manual-initialization for detailed explanations.