I am upgrading my app from Ionic 2.0.0-beta.20 to Ionic 2.0.0-rc.3 following this.
The guide says the following:
Import and add each of your custom components and pipes to the
declarations array in src/app/app.module.ts.
Import and add each of your providers to the providers array in
src/app/app.module.ts.
Remove any use of the providers, pipes and directives arrays in
#Component.
Question 1
In the old Ionic 2.0.0-beta.20 version, all the artifacts were just in the app/pages folder. With Ionic 2.0.0-rc.3, should they all just be in the src/pages folder with all the pages, or should they be seperated somewhere else?
Question 2
If I remove all directives from the #Component section of each page, where will those directives be defined?
e.g.
#Component({
templateUrl: 'review.html',
providers: [RatingService, JobService, UtilityService],
directives: [REACTIVE_FORM_DIRECTIVES, RatingComponentUpdateable, ControlMessages]
})
Regarding the question 1, actually you can decide how your project structure will be, and place the files where you want according to that (the only change will be in the path you use in the import statements). Ionic's default project's structure organizes things in terms of the type so by default you'd have something like this:
src
...
pages
pipes
providers
...
One of the easiest ways to find out where to put things, is just by using the ionic generate ... customName command where the three dots can be page, provider, pipe and directive. That would create the artifact and place it where it should be.
You can also take a look at the conference app to know how Ionic team organizes the project and where everything is located.
That being said, I've been working on projects where things were organized in terms of features, so the project structure was something like this:
src
feature1
page1FromFeature1
page2FromFeature1
modelFromFeature1
providerFromFeature1
feature2
...
shared
providers
pages
directives
pipes
This is actually how Angular2 recommends to organize the project in the Angular2 Style Guide.
Regarding the question 2, directives should be included in the NgModule declarations array like this:
#NgModule({
declarations: [
MyApp,
// Pages
...
// Pipes
...,
// Directives
...
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
// Pages
...
],
providers: [
// Providers
...
]
})
export class AppModule {}
Related
I am new to webpack and trying to figure out how to have the code splitting working.
I have a large bundle created from react-native-web and I want to split it into two smaller ones. One will include all node_modules and the other one my custom code.
Please note that my app has a single entry point and I do not require dynamic import at the moment.
I have tried adding the following into my webpack configuration
optimization: {
splitChunks: {
chunks: 'all'
}
}
This created two bundles, however my app is not rendered in the browser. Do I have to somehow reference the second bundle from the first one? Does anyone have a working example?
I have found the solution!
I had to add chunkFilename with the newly created chunk name as follows:
output: {
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
i'm developing my first Angular2 app and i'm using this folders structure:
components
component1
home.component.ts
home.component.html
home.component.scss
I'm using Gulp to run tasks for building the app. The final folders structure will be this one:
scripts
somefile1.js
somefile2.js
...
styles
mine.css
vendor.css
index.html
favicon.ico
Can you tell me what is the best way to incorporate HTML templates within Javascript files?
Besides i would be able to easily debug code, so i would see the original folders structure in browser's inspection tools.
I'm currently using gulp-sourcemaps plugin and sourceMap option set to true for Typescript compiler to do the same for Styles and Scripts.
What node plugins could i use to reach this purpose for HTML templates?
I've used gulp-angular-embed-templates on multiple projects with great success.
Here is an example task:
gulp.task('embed-templates', () => {
gulp.src('app/**/**.js')
.pipe(embedTemplates({sourceType:'js', minimize: {quotes: true, empty: true}}))
.pipe(gulp.dest('app/'));
});
I am trying to separate my admin code from my public code, I want to create 2 different directories in my app folder and resources folder, 1 directory named backend which contains all my admin code and another named frontend which contains public related code.
Each directory will have their own separate controllers.
Basically something like this:
-App
--frontend
--backend
-resources
--views
---frontend
---backend.
If there is a better way to do this i would also like to know.
By default you composer.json is autoload all in app. So you can make the structure which you described above.
Frontend and backend separating usually used for Controllers, in this case you need to make a correct namespace.
With views you would'n have any porblems. Just make a correct path when you calling your views.
For example:
view(frontend/index); // you can use dot instead of /
Currently, all my angular material HTML attributes are highlighted in yellow with WebStorm 9 (Mac OS X Yosemite) warning: "Attribute [name] is not allowed here".
How can I teach WS to automatically recognize these attributes as valid? I am aware that I can add each one one-by-one to the list of custom attributes, but was hoping that there would be a better way to do this.
UPDATE:
Just wanted to clarify that this issue applies to Angular Material project, and not the AngularJS itself.
You need to add the angular-material.js file as a Library in WebStorm:
Open Preferences (Mac: Cmd+,, Win/Linux: Ctrl+Alt+S)
Go to Languages & Frameworks > JavaScript > Libraries
Click Add and then press the + icon
Find angular-material.js in your node_modules folder
Add a Name and a version and press Ok
Now you will have completions for all elements and attributes that have an #ngdoc documentation in the angular-material source code.
Usage
Start typing and you will see the completions:
Pressing F1 (Ctrl+Q on Win/Linux) will also show some docs, if available in the source code:
Important note
Not all features are properly documented, the following won't show up (unless you already used them) cause they are defined dynamically in a loop, with no #ngdoc for them:
var API_WITH_VALUES = [ "layout", "flex", "flex-order", "flex-offset", "layout-align" ];
var API_NO_VALUES = [ "show", "hide", "layout-padding", "layout-margin" ];
So for these you'd have to add them as a custom attribute (Alt+Enter > "Add flex to custom html attributes").
Environment
Tested on a Mac OS X 10.11.4 using WebStorm 2016.1.1, but this should work for older versions as well.
I am using PHPStorm, which is a sister Project of WebStorm, but it should work the same way.
You maybe need to add the Library:
File
Settings
Languages & Frameworks
Javascript
Librarys
Add here AngularJS
If this does not work, you can add them manually:
Follow this Steps:
File
Default Settings
Editor
Inspection
HTML
Unknown HTML tag attributes
To the right you will see in Options "Custom HTML tag attributes". Enter here the attributes you want to allow.
I highly recomend you to install the Angular.js plugin:
Go to menu File > Settings (or ctrl + alt + S if you're on Windows);
Select Plugins in the window that'll open;
Click in the Browse Repositories button;
Type AngularJS in the search field. Select the plugin;
Click Install Plugin.
The plugin is incumbed to read #ngdoc annotations present in ngMaterial sources and create documentation for their directives.
It seems to support WebStorm and other IDEs, but I could not find it in the plugin registry while filtering by other IDEs. Maybe it'll work inside WebStorm...
Anyway, this is what you get:
You have also a plugin that helps a lot, check it out. It helps a lot
Angular material v2, Teradata covalent v1, Angular flex layout v1 & Material icon live templates
And with the solution provided by #Alex Ilyaev gives a lot of help.
But its no perfect.
Hope it helps.
Currently I don't think that idea's AngularJS plugin understands angular-materials attribute extensions.
It does understand the directives i.e. control click <md-button ...> and the directive (custom tag) is found.
For now you will have to add the attributes af custom attributes in order to get a "green" page.
Given that ember-cli uses ES6 modules syntax to import other JavaScript files, is it also possible to use this same syntax to import non-JavaScript files, such as JSON files or other text files?
Assume I have a JSON file named "foo.json" in my current directory. How could I import the contents of that file into a variable within my current JavaScript file? I've tried, without success, several variations of:
import foo from 'foo.json';
if (typeof foo === 'object') {
// Success
} else {
// import failed
}
Is it possible to import non-JavaScript files into the current file using the import statement or any other means?
No it's not. The ES6 modules syntax to import stuff also needs the requested object to be properly exported, which your json-files or text-files won't be. Also, since we don't really have ES6 in browsers yet, all those nifty statements are converted to commonjs-modules when building your project.
As I see it you have two options for this.
Putting the files in your public-folder and load them via ajax is the simple solution though not very elegant.
The cool option would be to add a preprocessor of your own that wraps your json-files in a proper export-statement as a build-step. That would be quite a lot of more work though and might require some deep diving into ember-cli and broccoli to attach it at the right time.
Yes, ember-cli can import JSON and non-JS files as long as you have the proper plugin.
This one allows the import of JSON files:
https://github.com/IvyApp/ember-cli-json-module
... and this one works for YAML: https://github.com/joankaradimov/ember-cli-yaml-module.