-
Notifications
You must be signed in to change notification settings - Fork 24
Ionic_Adding Images
In this section I'll describe how to add new images to Ionic2 project, and how to use them in pages.
First we need to add an image to the project. For this, and all future images, we'll add a new img directory inside our app directory. Now we can add our image to this directory.
In order for our new img directory, and all images inside it, to compile, we need to update the our gulp
script inside the gulpfile.js.
//code omitted for brevity
gulp.task('watch', ['clean'], function(done){
runSequence(
['sass', 'html', 'fonts', 'scripts', 'images'],
function(){
gulpWatch('app/**/*.scss', function(){ gulp.start('sass'); });
gulpWatch('app/**/*.html', function(){ gulp.start('html'); });
buildBrowserify({ watch: true }).on('end', done);
}
);
});
gulp.task('build', ['clean'], function(done){
runSequence(
['sass', 'html', 'fonts', 'scripts', 'images'],
function(){
buildBrowserify().on('end', done);
}
);
});
//code omitted for brevity
gulp.task('images', function(){
return gulp.src('app/img/**/*.+(jpg|png|svg)')
.pipe(gulp.dest('www/build/img'));
});
All we did here is defined a new gulp.task
called images
, and told it to get all the files ending with jpg
, png
, or svg
inside the app/img and its subfolders, and send it to www/build/img directory.
We also have to tell gulp to execute this task, and we did that by adding the images
task to the runSequence
.
Finally, we are ready to reference an image in our code:
<img src="build/img/image_name.png"/>
It took me some time to figure out how to make gulp to compile the images. I also lost a lot of time trying to guess the path to the image, as <img src="../../img/image_name.png"/>
, and similar variations, didn't work.
I'm a little bit wary of gulp, as I'm not really sure how it compiles all the classes I'm adding to the project, so I'm not yet sure how to add a new folder with components, that isn't inside the app/pages directory.
- Android
- Getting Started
- Project Structure
- Gradle
- Menu
- Theming
- Login Screen
- Menu & Navigation
- Importing Library From GitHub
- Creating Reusable Layouts
- Adding New Icons
- Profile Screen
- Chat Screen
- Contacts Screen
- Pending Invites Screen
- Settings Screen
- Add Library Dependency
- Discover Users Screen
- Splash Screen
- Auth0
- Authentication Logic
- Profile Screen Logic
- Send Feedback
- Authenticated to Firebase via Auth0
- Saving User Info to Firebase
- Storing User Connection Info to Firebase
- Calculating Distance Between Users
- Chat Logic
- Handling Device Rotation
- Android Other
- Ionic
- Getting Started
- Project Structure
- Menu
- Theming
- Login Screen
- Adding Images
- Creating Reusable Layouts
- Adding New Icons
- Profile Screen
- Contact Screen
- Elastic Textarea
- Chat Bubble
- Chat Screen
- Contacts Screen
- Pending Invites Screen
- Settings Screen
- Discover Users Screen
- Splash Screen
- Animations
- Auth0
- Storing User Data
- Profile Screen Logic
- Send Feedback
- Update to Ionic RC0
- Reimplemented Auth0 with Ionic RC0
- Authenticated to Firebase via Auth0
- Saving User Info to Firebase
- Storing User Connection Info to Firebase
- Calculating Distance Between Users
- Chat Logic
- Handling Device Rotation
- Ionic Other
- Version Updating
- Cordova
- Other
- Messaging