Giter VIP home page Giter VIP logo

angular-tribute's Introduction

angular-tribute

An AngularJS 1.5+ wrapper for ZURB's Tribute library for native @mentions.

Install

$ npm install angular-tribute --save

or include the UMD build, hosted by unpkg in a <script> tag. You will also need to include the main ZURB Tribute library:

<script src="js/tribute.js"></script>
<script src="//unpkg.com/angular-tribute"></script>

Usage

import Angular from "angular";
import AngularTribute from "angular-tribute";

angular
  .module('myApp', [])
  .directive('angularTribute', AngularTribute)

In your controller:

  $scope.people = [
    { name: 'Adam',      email: '[email protected]' },
    { name: 'Amalie',    email: '[email protected]', },
    { name: 'Estefanía', email: '[email protected]', },
    { name: 'Adrian',    email: '[email protected]', },
    { name: 'Wladimir',  email: '[email protected]', },
    { name: 'Samantha',  email: '[email protected]', },
    { name: 'Nicole',    email: '[email protected]', },
    { name: 'Natasha',   email: '[email protected]', },
    { name: 'Michael',   email: '[email protected]', },
    { name: 'Nicolás',   email: '[email protected]', }
  ];

  $scope.tributeConfig = {
    lookup: 'name',
    fillAttr: 'name'
  }

  $scope.tributeOnReplaced = function () {
    console.log('text replaced!');
  };

  $scope.tributeOnNoMatch = function () {
    console.log('no match found in collection!');
  };

And in your view you can add:

  <textarea angular-tribute
    values="$ctrl.people"
    options="$ctrl.tributeConfig"
    on-replaced="$ctrl.tributeOnReplaced"
    on-no-match="$ctrl.tributeOnNoMatch"
  ></textarea>

The options, on-replaced and on-no-match parameters are optional.

The values array should be an array of objects that contain a key and value like so:

[
  {key: "Phil Heartman", value: "pheartman"},
  {key: "Gordon Ramsey", value: "gramsey"}
]

You can modify this structure using the built-in Tribute options.

Events

Tribute broadcasts two events — a tribute-replaced event, and a tribute-no-match event (see docs here). For your convenience, you can bind to these events by passing a function to on-replaced or on-no-match attributes respectively.

License

MIT © ZURB

angular-tribute's People

Contributors

mrsweaters avatar npmcdn-to-unpkg-bot avatar

Watchers

James Hulse avatar James Cloos avatar  avatar

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.