dano2
March 28, 2015, 7:12am
1
This is my first attempt at writing a controller. The following code worked until I added the two $ionicHistory references. Doing that gave me:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.17/$injector/unpr?p0=%24ionicHistoryProvider%20<-%20%24ionicHistory
I thought including the ionic dependency would be all that was required. Any thoughts?
var fp = angular.module('freshlypressed', ['ionic']);
fp.controller('BlogListCtrl', ['$scope', '$ionicHistory', '$http', function($scope, $ionicHistory, $http){
console.log('in BlogListCtrl');
//$ionicHistory.clearHistory();
}]);
hi @deno
you can also define controller like
fp.controller(‘BlogListCtrl’, function($scope, $ionicHistory, $http){
});
dano2
March 28, 2015, 9:57am
3
Hi Jari. Is that related to the error I’m getting? AFAIK, the annotation approach is “better” practice to prevent trouble when minifying your JS. Is that not correct?
Thanks
dano2
March 29, 2015, 5:31am
4
That did not fix the error. Any other suggestions?
No dano you are not using wrong approach.
Your approach is better with minified js.
I had try your code and it is working. No any error for injection.
I had created ionic starter project and put your controller in app.js file.
You can create is by ionic start cmd
.JS FILE
// Ionic Starter App
var fp=angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
fp.controller('BlogListCtrl', ['$scope', '$ionicHistory', '$http', function($scope, $ionicHistory, $http){
$scope.name="dano2";
console.log('in BlogListCtrl');
//$ionicHistory.clearHistory();
}]);
HTMLCODE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content class="has-header" ng-controller="BlogListCtrl">
<h1>{{name}}</h1>
</ion-content>
</ion-pane>
</body>
</html>
It is showing in BlogListCtrl in console. and deno2 on screen.
I had additionally put $scope.name to check controller is working or not.