angularjs - How to properly check when Angular loads HTML into DOM dynamically -
angularjs - How to properly check when Angular loads HTML into DOM dynamically -
i having hard time getting application event-based whilst using angularjs. in jquery, extremely easy check when dom loaded document, event listeners can bound new dom. however, trying same effect in angular , cannot find way not "hacky".
for example, using ng-include
add together partial views dom when overlay added document , single <div>
displayed user interact with. however, cannot center <div>
correctly because need run javascript after loaded in order center properly.
i tried using ng-init="center()"
in partial views, don't think angular re-compiling view after gets added, hence ng-init
never getting called. can event-based functionality without doing weird hack?
you're doing did when first started angular - thinking in jquery way.
see post lot more info in 'thinking' differently how “think in angularjs” if have jquery background?
with regards specific issue. can create directive attach, way of attribute, div
. then, in link
object of return, directive, set css - using javascript if needed.
i.e this, pseudo-code
app.directives('mydirective', function()){ return{ restrict: 'a', link: function(scope, elem, attr){ //do elem - it's angular.element can // interact using jquery methds. // such elem.hide(); // can search through kid nodes in same // way jquery, elem.each(..... } } }
then on div
<div my-directive></div>
ultimately have 'think' differently.
i recommend not using jquery in directives used 'angular' way
update
as per comments. if want dynamically alter template directive using - in case templateurl, can like:
app.directives('mydirective', function()){ return{ restrict: 'a', template: '<div ng-include="settemplate()"></div>', link: function(scope, elem, attr){ scope.settemplate = function(){ // logic here... homecoming 'overlay.html'; } } } }
angularjs
Comments
Post a Comment