Ok-edited to add code.
I cannot get javascript functions to bind to element in an html page that is an angular include.
This works:
<button id="toggleMessage">Click Me</button>
<script src="/Scripts/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
var myapp = angular.module('myapp', []);
var globalFunctions = function () {
var init = function () {
toggleMenuLeft();
};
var toggleMenuLeft = function () {
$('#toggleMessage').bind('click', function (e) {
alert("Hello");
});
};
return {
init: init,
};
}();
//Load global functions
$(document).ready(function () {
globalFunctions.init();
});
</script>
Once I move that button into an include it no longer works. I tried changing .click to .on but still doesn't work:
#ParentPage.html
<body ng-app="myapp">
<div ng-include="'/IncludePage.html'"></div>
<script src="/Scripts/jquery-2.1.0.min.js"></script>
<script src="/Scripts/angular.js"></script>
<script type="text/javascript">
var myapp = angular.module('myapp', []);
var globalFunctions = function () {
var init = function () {
toggleMenuLeft();
};
var toggleMenuLeft = function () {
$('#toggleMessage').bind('click', function (e) {
alert("Hello");
});
};
return {
init: init,
};
}();
//Load global functions
$(document).ready(function () {
globalFunctions.init();
});
</script>
</body>
#IncludePage.html
<button id="toggleMessage">Click Me</button>
The real code, called from a topnav include which looks for a #toggle-left on a leftnav include. https://gist.github.com/anonymous/11084106
#RealCode - For Matt
var toggleMenuLeft = function () {
$(document).on('click', '#toggle-left', function (e) {
if (!$('.sidebarRight').hasClass('.sidebar-toggle-right')) {
$('.sidebarRight').removeClass('sidebar-toggle-right');
$('.main-content-wrapper').removeClass('main-content-toggle-right');
}
$('.sidebar').toggleClass('sidebar-toggle');
$('.main-content-wrapper').toggleClass('main-content-toggle-left');
e.stopPropagation();
});
};
#toggle-leftdoesn't exist when the code runs. You have to bind after the view has been loaded..on()instead of.bind()?