Giter Club home page Giter Club logo

ng-required-params's Introduction

ng-required-params

NPM Version Dependencies Contributions Welcome

A tiny angular module that enforces required parameters on function calls by utilizing ES6 default parameters.

Install

Install using npm or bower:

$ npm install ng-required-params --save
$ bower install ng-required-params --save

ng-required-params has no dependencies other than an ES6 codebase and Angular itself.

Usage

Simply require ng-required-params as a dependency for your app or any angular module.

angular
  .module('MyApp', ['ng-required-params'])
  .controller('MyController', ['$scope', 'ngRequired', function ($scope, ngRequired) {
    $scope.incrementCounter = (counter = ngRequired`counter`) => {
      console.log('Current count: ' + counter++);
    };
      
    $scope.incrementCounter(5); // Logs ==> Current count: 6
    $scope.incrementCounter();  // Error ==> Missing parameter: counter
}]);

Since required parameters are fundamental and may be often used, it makes sense to make the call to the service as short and easy-to-type as possible. Therefore it is recommended to use template literal syntax foo´string´ for calling ngRequired instead of the normal round brackets syntax foo('string'). You may also want to name the imported module as "ngReg" or "req" instead of "ngRequired" to save even more keystrokes.

Use with a module loader

If you are using a module loader, you can import the module name when requiring it in angular. This works with any AMD/UMD/CommonJS module loader.

import ngRequiredParamsModule from 'ng-required-params';

angular.module('myModule', [ngRequiredParamsModule.name]);

ng-required-params's People

Contributors

dependabot[bot] avatar schnogz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

ng-required-params's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.