如何在Ionic / AngularJs应用程序中包含和使用节点模块? [英] How to include and use node modules in your Ionic / AngularJs app?

查看:74
本文介绍了如何在Ionic / AngularJs应用程序中包含和使用节点模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ionic应用程序,我想在我的控制器中包含 angular-base64 的节点模块,甚至包装在一个有角度的服务等。我已经开始运行

I have an Ionic app and I'd like to include the node module angular-base64 to use in my controllers, or even wrap inside an angular service etc. I've gone ahead and ran

npm install angular-base64

继续安装包含 angular-base64.min.js c> / myIonicApp / node_modules / 内的文件。所以该文件的完整路径是 /myIonicApp/node_modules/angular-base64/angular-base64.min.js

Which went ahead and installed the folder containing angular-base64.min.js file inside /myIonicApp/node_modules/. So the full path to the file is /myIonicApp/node_modules/angular-base64/angular-base64.min.js .

然而,当我尝试在我的一个控制器中使用模块时,这样:

However when I try and make use of the module in one of my controllers like this:

app.controller('myController', ['$scope', '$base64',
  function($scope, $base64) {

    //$base64... 

  }
]);

我不知道我在说什么。我是否必须做其他事情才能使其发挥作用?也许我的 app.js

It has no idea what I'm talking about. Do I have to do something else to get this to work? Perhaps something in my app.js?

推荐答案

接受的答案是 Ionic V2 不再准确, .bowerrc 已从默认安装中删除。

The accepted answer is no longer accurate for Ionic V2 and the .bowerrc was removed from default installation.

来自官方Ionic V2文档的以下是您现在的操作方法

Here is how you do it now, from the official Ionic V2 docs.


要将第三方库添加到应用程序,请运行以下命令:



npm install --save

To add a third party library to an app, run the following command:

npm install --save

例如:使用导入的函数

//命名导出模式

从'theLibraryName'导入{myFunction};

import { myFunction } from 'theLibraryName';

...

//使用导入的功能

myFunction();

myFunction();

这篇关于如何在Ionic / AngularJs应用程序中包含和使用节点模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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