I would like to make a small Angular app from within a Polymer web component.
I wrote a quick test to see if this is trivially possible:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<script type="text/javascript" src="../../bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../../bower_components/angular/angular.js"></script>
<polymer-element name="test-component">
<template>
<div ng-app="app">
<div ng-controller="AppCtrl">
... {{test}} ...
</div>
</div>
</template>
<script>
!function () {
Polymer('test-component', {
ready: function () {
var app = angular.module('app', [])
app.controller('AppCtrl', function ($scope) {
$scope.test = 'testing';
});
}
});
}();
</script>
</polymer-element>
Unfortunately, this does not work. The page displays ... ... instead of ... testing .... No errors are shown in the console.
I tried taking the Angular code out of the ready hook and above the Polymer function entirely. A console.log(angular, app) in ready was returning the correct things, but yielded the same result as before.
I also tried to put the Angular code inside the template at the very bottom, essentially treating the <template> tag like a <body> tag. This also resulted in the same behavior.
Is it possible to use Angular in a web component? If possible, I would like to be able to use the encapsulation qualities (shadow DOM and such) of web components while still using AngularJS.