Dynamically add directives in AngularJS
For a walkthrough see http://blog.fourtonfish.com/post/74055065673/dynamically-add-directives-in-angularjs-no-jquery
by Thunder Hemlock
HTML
<section ng-app="myApp" ng-controller="MainCtrl">
</section>
</section>
CSS
section {
padding: 2em;
}
button {
padding:0.3em;
margin: 0.3em;
}
JavaScript
var myApp = angular.module('myApp', []);
function MainCtrl($scope) {
var x = "fromWheel";
$scope.showAd = function (x) {
console.log('showAd FIRED!');
alert('x = ' + x);
if (x = 'fromWheel') {
if ($scope.thisSelectedTermObj[0].name === 'Imagery') {
alert('Imagery fromWheel');
if (AdMob) AdMob.showInterstitial();
} else if ($scope.thisSelectedTermObj[0].name === 'Syntax') {
alert('Imagery fromWheel');
if (AdMob) AdMob.showInterstitial();
} else if ($scope.thisSelectedTermObj[0].name === 'Conceit') {
alert('Imagery fromWheel');
window.adcolony.showFullScreenAd();
} else if ($scope.thisSelectedTermObj[0].name === 'Meter') {
alert('Imagery fromWheel');
window.adcolony.showFullScreenAd();
} else if ($scope.thisSelectedTermObj[0].name === 'Symbolism') {
alert('Imagery fromWheel');
window.adcolony.showFullScreenAd();
} else {
alert('Imagery fromWheel');
console.log('No ad shown fromWheel');
}
} else if (x = 'fromExamples') {
if ($scope.thisSelectedTermObj[0].name === 'Conventions') {
alert('Imagery fromWheel');
window.adcolony.showFullScreenAd();
} else if ($scope.thisSelectedTermObj[0].name === 'Characterization') {
alert('Imagery fromWheel');
window.adcolony.showFullScreenAd();
} else {
alert('No ad shown fromExamples');
}
} else if (x = 'fromIllustrated') {
if ($scope.thisSelectedTermObj[0].name === 'Conventions') {
alert('Imagery fromWheel');
window.adcolony.showFullScreenAd();
} else if ($scope.thisSelectedTermObj[0].name === 'Characterization') {
...