JSFiddle - React, Tailwind, and code Playground
by marcolepsy
HTML
<div ng-app="app">
<div ng-controller="Ctrl">
<my-template></my-template>
</div>
<!-- my-template.html -->
<script type="text/ng-template" id="my-template.html">
<label ng-click="test(blah)">Click</label>
<label ng-click="test(anotherBlah)">Click</label>
</script>
</div>
JavaScript
angular.module('app', [])
.controller('Ctrl', function Ctrl1($scope, $rootScope, BlahFactory) {
BlahFactory.setValue('another blah');
})
.constant('blah', 'blah')
.factory('BlahFactory', function() {
var blah = {
value: 'blah'
};
blah.setValue = function(val) {
this.value = val;
};
blah.getValue = function() {
return this.value;
};
return blah;
})
.directive('myTemplate', function() {
return {
restrict: 'E',
templateUrl: 'my-template.html',
scope: {},
controller: ["$scope", "blah", "BlahFactory", function($scope, blah, BlahFactory) {
$scope.blah = blah;
$scope.anotherBlah = BlahFactory.getValue();
$scope.test = function(arg) {
console.log(arg);
}
}]
};
});