Im try to use Oboe.Js and Angular.Js together
Here is my sample code which is working correctly..
angular.module('myApp', ['ng-oboe'])
.config(function (oboeProvider) {
/* If we were so inclined, we could change the oboe defaults here - headers, etc. */
// oboeProvider.defaults = {};
})
.controller('myCtrl', function ($scope, oboe) {
$scope.test = "Yo.";
$scope.items = [];
oboe.get('http://localhost:4243/containers/f78257b77b21/stats')
.start(function (data, etc) {
})
.node('!', function (value) {
})
.done(function (value) {
console.log("It works! ", value.read);
$scope.items.push(value);
})
.fail(function (error) {
console.log("Error: ", error);
});
});
But when I try to use these code with my actual project controller. I'm getting this error. I can't figure out Why I'm getting this.
Error : TypeError: Cannot read property 'get' of undefined
module.js
angular.module('RDash', ['ui.bootstrap', 'ui.router', 'ngCookies','ng-oboe'])
.config(function (oboeProvider) {
/* If we were so inclined, we could change the oboe defaults here - headers, etc. */
// oboeProvider.defaults = {};
});
stats-ctrl.js
angular
.module('RDash')
.controller('StatsCtrl', ['$scope', '$stateParams', StatsCtrl]);
function StatsCtrl($scope, $stateParams, oboe) {
var id = $stateParams.id;
$scope.myData = [];
$scope.items = [];
console.log('http://localhost:4243/containers/' + id + '/stats');
oboe.get('http://localhost:4243/containers/' + id + '/stats')
.start(function (data, etc) {
console.log("Dude! We're goin'!", data, etc);
})
.node('!', function (value) {
})
.done(function (value) {
console.log("It works! ", value.read);
})
.fail(function (error) {
console.log("Error: ", error);
});
}
Inside your controller function you have obe
factory has no value(undefined), because it haven't been injected inside DI array.
angular
.module('RDash')
.controller('StatsCtrl', ['$scope', '$stateParams', 'obe', StatsCtrl]); //<-inject obe here
function StatsCtrl($scope, $stateParams, oboe) {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.