Use Vue Components in Angular 1.x

2.2.1 · maintenance · verified Sun Apr 19

ngVue is a JavaScript module designed to integrate Vue 2 components within AngularJS 1.x applications. It provides a bridge, enabling developers to use Vue's reactive data binding and component-based architecture within existing Angular 1.x codebases. This allows for a gradual migration of view layers from Angular 1.x to Vue 2, addressing common performance bottlenecks related to Angular's scope watchers and offering a more predictable one-way data flow. The current stable version is 2.2.1. While the project sees occasional maintenance releases to address minor issues and improve compatibility (e.g., ESM support), its primary use case targets older, established Angular 1.x applications rather than new development. Key differentiators include its `vue-component` directive and `createVueComponent` factory, specifically tailored for interop between these two legacy frameworks. For Vue 3 support, users are explicitly directed to use the separate `ngVue3` package.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate a Vue 2 component into an AngularJS 1.x application using `ngVue`, passing props and handling events.

import angular from 'angular';
import Vue from 'vue';
import 'ngVue';

// Define a simple Vue component
const MyGreetingComponent = {
  template: `
    <div>
      <h3>Hello from Vue!</h3>
      <p>{{ message }}</p>
      <button @click="emitEvent">Click me (Vue)</button>
    </div>
  `,
  props: ['message'],
  methods: {
    emitEvent() {
      this.$emit('vue-clicked', 'Hello from Vue event!');
    }
  }
};

// Register ngVue and define the Angular app
angular.module('myApp', ['ngVue'])
  .controller('MyController', function($scope, $rootScope, createVueComponent) {
    // Expose the Vue component to ngVue via $rootScope.components
    // This is a common pattern for ngVue to find components by name
    $rootScope.components = {
      MyGreetingComponent: MyGreetingComponent
    };

    $scope.angularMessage = 'Data from Angular scope.';
    $scope.vueData = {
      message: 'This prop is passed from Angular to Vue.'
    };
    $scope.vueEvents = {
      'vue-clicked': function(payload) {
        console.log('Vue component clicked! Payload:', payload);
        alert('Vue component received event: ' + payload);
      }
    };
  });

// To use in HTML (assuming an index.html file):
// <div ng-app="myApp" ng-controller="MyController">
//   <h2>Angular App with Vue Component</h2>
//   <p>Message from Angular: {{ angularMessage }}</p>
//   <vue-component name="MyGreetingComponent" v-props="vueData" v-on="vueEvents"></vue-component>
// </div>

view raw JSON →