jquery - Execute javascript after loading template into view AngularJS -


i'm new angular , trying figure out how run javascript specific 1 template.

if include script in main page, doesn't work bevause specifric dom relevant template has not been loaded yet.

i've tried event delegation that's not working.

is there way include script inside controller runs after template called has loaded?

this code:

        .when("/user-form", {         templateurl: "templates/form.html",          controller: "formcontrol"})           app.controller('formcontrol', function($scope) {          }); 

usually need declare directives (those independent (or semi-independent) template-blocks have own encapsulated logic.

you need register directives, , better done using ddo - directive definition object (check snippet below)

1st there link function, part of ddo (directive definition object) in angular, , happens once dom been rendered.

app.directive('helloworld', function() { return { restrict: 'ae', templateurl: 'templates/mytemplate.html', controller: controllerfunction, link: function(scope, elem, attrs) { // link function code } }; });

there plenty of guides link function , it's place in rendering cycle.

there ways deal async data binding within controller, , creates better , more maintenable practice, link function structure intends more dom-manipulative , jquery-like.

as understand question need read more material on angular directives, templates, data binding, ddo , ddo structure , it's standard properties , methods.

good luck!


Comments