ng-surveys
Getting started
First install through npm:
npm install --save ng-survey
Next install peer dependencies
npm install --save @angular/cdk @ckeditor/ckeditor5-angular @ckeditor/ckeditor5-build-classic bootstrap ngx-bootstrap jquery @fortawesome/fontawesome-free
Import the ng-survey module into your apps module:
;;
Add Bootstrap and Font Awesome to your angular.json to the styles and scripts array under build target
NgBuilderViewerComponent
What is it? - Where your users build a survey.
Example
Options
An object with 6 optional properties:
- importSurvey
- Object with callback property to import a new survey.
- Callback should return type of NgSurveyState or ***Observable***.
- surveyButtons
- Array of objects used to specify a custom survey buttons.
- Object has 4 properties: title, icon, text, and callback.
- Callback has one parameter of NgSurveyState type.
- importPage
- Object with callback property to import a new page.
- Callback should return type of IPageAndElementAndOptionAnswers or ***Observable***.
- pageButtons
- Array of objects used to specify a custom survey buttons.
- Object has 4 properties: title, icon, text, and callback.
- Callback has one parameter of IPageAndElementAndOptionAnswers type.
- importElement
- Object with callback property to import a new element.
- Callback should return type of IElementAndOptionAnswers or ***Observable***.
- elementButtons
- Array of objects used to specify a custom survey buttons.
- Object has 4 properties: title, icon, text, and callback.
- Callback has one parameter of IElementAndOptionAnswers type.
Options Example
NgModelViewerComponent
What is it? - Where users can view the survey model.
Example
NgSurveyViewerComponent
What is it? - Where users can interact with the built survey.
Example
NgSurveysService
What is it? - A service that provides methods to retrieve the survey state. Methods listen to the latest state changes in the stream and returns changes that occur to a specific state.
getNgSurveyState()
- Listen to the latest state changes in the stream.
- @returns: Observable<NgSurveyState>
getSurveyChanges()
- Listen to the latest survey state changes in the stream.
- @returns: Observable<INgSurvey>
getPagesChanges()
- Listen to the latest pages state changes in the stream.
- @returns: Observable<IPageMap>
getElementsChanges()
- Listen to the latest element state changes in the stream.
- @returns: Observable<IElementsMaps>
getElementsByPageIdChanges()
- Listen to the latest element state changes of a page in the stream.
- @param: pageId to retrieve elements of a specific page
- @returns: Observable<IElementsMap>
getOptionAnswersChanges()
- Listen to the latest option answers state changes in the stream.
- @returns: Observable<IOptionAnswersMaps>
getOptionAnswersByElementIdChanges()
- Listen to the latest option answers state changes of an element in the stream.
- @param: elementId to retrieve option answers of a specific element
- @returns: Observable<IOptionAnswersMap>
NgSurveysService Example
; ...
Development
- Clone repo
- Install dependencies:
npm install
Building the Library
- Before we can use ng-surveys library we need to build it:
ng build ng-surveys
- With Angular CLI v6.2 we can use the --watch flag so that every time a file changes Angular CLI performs a partial build that emits the amended files:
ng build ng-surveys --watch
- Run the application project (demo app to test our library):
ng serve
- Navigate to
http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Code scaffolding
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Build
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Running unit tests
Run ng test
to execute the unit tests via Karma.
Running end-to-end tests
Run ng e2e
to execute the end-to-end tests via Protractor.
Further help
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.