无法将$ ionicHistory注入我的angularjs控制器 [英] Cannot inject $ionicHistory into my angularjs controller

查看:137
本文介绍了无法将$ ionicHistory注入我的angularjs控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Angularjs / Ionic应用程序中的Controller中使用$ ionicHistory.goBack()。当我尝试将其注入我的控制器中时如下所示

I am trying to utilize $ionicHistory.goBack() in a Controller in my Angularjs/Ionic app. When I try and inject it into my controller as below

app.controller('ClockInController', function($scope, $http, JobData, Data, $rootScope, $interval, $ionicHistory)

我运行的应用程序错误如下:

and I run the app I get the error below:

未捕获错误:[$ injector:unpr]未知提供者:$ ionicHistoryProvider< - $ ionicHistory http://errors.angularjs.org/1.3.0/ $ injector / unpr?p0 =%24ionicHistoryProvider%20%3C-%20%24ionicHistory , http:// localhost:8100 / vendors / onsen / js / angular / angular。 js ,行:4116

Uncaught Error: [$injector:unpr] Unknown provider: $ionicHistoryProvider <- $ionicHistory http://errors.angularjs.org/1.3.0/$injector/unpr?p0=%24ionicHistoryProvider%20%3C-%20%24ionicHistory, http://localhost:8100/vendors/onsen/js/angular/angular.js, Line: 4116

推荐答案

angular.module('myApp', ['ionicModuleOrWhatever'])
.controller('ClockInController', ['$ionicHistory', function ($ionicHistory) {
    // Do something with $ionicHistory
}]);

我用你提供的链接想出了这个: http://errors.angularjs.org/1.3.0/$injector/unpr?p0=%24ionicHistoryProvider%20%3C-%20%24ionicHistory 。文档可能有点密集,但它是第一行

I figured this out with the link you provided: http://errors.angularjs.org/1.3.0/$injector/unpr?p0=%24ionicHistoryProvider%20%3C-%20%24ionicHistory. Documentation can be a bit dense but it was the first line

更新:你提到你从github复制了代码,我找到了你的问题。而不是克隆你必须复制你认为你应该的文件 - 但你复制了错误文件

update: you mentioned you copied the code from github, I found your issue. Instead of cloning you must have copied the file you thought you were supposed to - but you copied the wrong file.

由于您的错误未捕获的ReferenceError:未定义IonicModule,localhost:8100 /js/history.js,行:19 - 该文件包含以下第19行和第20行:

Due to your error Uncaught ReferenceError: IonicModule is not defined, localhost:8100/js/history.js, Line: 19 -- That file has The following lines 19&20:

IonicModule
.factory('$ionicHistory', [

对我来说,这个看起来像coffeescript,它没有编译。你复制的文件不是文件的发布版本。你需要此文件,而不是 ionic github项目包含一个gulpfile,这意味着他们正在使用一个构建工具。可能你复制了用于生成发布的文件该文件的版本,而不是该文件的发行版本。在像这样包含gulpfile或gruntfile的项目中,检查 / dist / 目录, / dest / 目录,发布目录,或 build / 目录,而是从那里复制文件。如果您不打算修改$ ionicHistory源代码,也可以复制该文件的 .min.js 版本。

To me, this looks like coffeescript, which is not compiled. The file you copied was not the release version of the file. You need this file, instead. The ionic github project contains a gulpfile, which means they are using a build tool. Likely you had copied the file that is used to generate the release version of the file, instead of the release version of the file. In projects like this that contain either a gulpfile or gruntfile, check for a /dist/ directory, a /dest/ directory, a release directory, or a build/ directory and instead copy the file from there. You can also copy the .min.js version of the file if you don't plan on modifying the $ionicHistory source code.

这篇关于无法将$ ionicHistory注入我的angularjs控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆