GithubHelp home page GithubHelp logo

leaflet-popup-angular's Introduction

leaflet-popup-angular

Use AngularJS in your Leaflet popups. Extends the built-in L.popup.

Supports Leaflet v1.0.0

For Leaflet 0.7.7 support see leaflet-popup-angular v0.1.2

See working examples.

Usage

Basic

	var popup = L.popup.angular({
		template: `
			<div>
				<h1>{{popup.$content.title}} - <small>{{popup.$content.name}}</small></h1>
				<div>
					My custom popup with controller. {{popup.hello}}
				</div>
			</div>
		`,
		controllerAs: 'popup',
		controller: ['$content', function($content){
			this.hello = 'Hello';
			$content.on(function(content){
				console.log('This executes on setContent', content);
			});
		}]
	}).setLatLng(latlng).setContent({
	    	'name': 'foo',
	    	'title': 'bar'
	    })
	    .openOn(map);

No Controller

	var popup = L.popup.angular({
		template: `
			<div>
				<h1>{{$content.title}} - <small>{{$content.name}}</small></h1>
				<div>
					My popup without a controller.
				</div>
			</div>
		`,
	}).setLatLng(latlng).setContent({
	    	'name': 'foo',
	    	'title': 'bar'
	    })
	    .openOn(map);

Note

For clarity, these examples are using template literals to represent multiline strings. Template literals are part of ES6 and are not supported by some browsers (notably IE). See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

This is a new package. We will be introducing support for angular's templateUrl soon and the examples will be reimplemented using this feature.

For production use at this time, either:

  • Use a bundler like webpack to insert the html into your template-- template: require('template.html')
  • Use template literals and a tool like babel to compile down to ES5
  • Use oldschool JavaScript strings in place of template literals

Dependency Injection

In addition to the rest of your Angular application's services, L.popup.angular also provides several of its own services through dependency injection to the controller.

  • $content Content object. Register callbacks for setContent() with $content.on()
  • $map Leaflet map object
  • $options The options params from L.popup.angular.

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.