On a blog about Phonegap+cordova+ionic environment, today to share a Cordova call native API article. Technically speaking, this is not very difficult, but some details without notice, or some of the steps do not know, then in the pit 1:30 will be difficult to climb out. So these two blogs are designed to help small partners save more time to do other meaningful things.
1. New Project
new project and add platform support has been mentioned in the previous blog, don't repeat it here.
2, the use of bower
first confirm whether Bower is installed,if not installed, open cmd name, enter npm install-g Bower.
Open The cmd command, enter Bower install Ngcordova, if the following message appears, the computer does not have gitinstalled, because the source code for Bower managed packages is hosted on the GitHub website.
Git installation, you can enter git for Windows directly in the search engine , download a git installation file, click Install, and put Git.exe Add to the environment variable, or you can download the GitHub Client tool directly,Gitshell. Specific installation methods can be self-search on the internet.
Here, by the way Bower Install JS Library, delete JS Library, see the way to install JS Library (The following three steps are not necessary, just as a small episode):
Enter the Bower install jquery command, install the jquery library file, and if the following information appears, the installation is successful:
Enter Bower list to view the installed JS library file:
Enter Bower Uninstall jquery to delete the JS library file you just installed:
Then enter the Bower List command and we will find that the jquery installation is no longer in the directory:
3, Installation Ngcordova
switch to the project directory, enter Bower install Ngcordova, the following message appears: (Some of the information in the picture is omitted, only the head and tail information).
For more information, refer to:http://www.haomou.net/2015/01/05/2015_ionic_ngCordova/
4. Add Camera Plugin
switch to the project directory, enter the Cordova plugin add cordova-plugin-camera command, and the following message appears, indicating that the installation was successful:
More plugin information:http://ngcordova.com/docs/plugins/camera/
5. Modify the project
after all the preparations have been completed, open the new Project project with the editor (I use webstorm here),
The first step: index.html manually introduced in Ng-cordova.js file.
Step Two: add Ngcordova dependencies in the controllers .
Step three: Add a button on the Details page to trigger a call to the camera operation.
Fourth step: add the Getcamera method to the controller that corresponds to the details page .
Fifth step: in cmd , enter the engineering directory, enter the Ionic run Android command, run on the phone.
6.
Phonegap+cordova+ionic calling native API