In AngularJS, any inline javascript code that included in HTML templates doesn't work

前端 未结 4 1981
孤城傲影
孤城傲影 2020-11-27 07:46

In AngularJS, any inline javascript code that included in HTML templates doesn\'t work.

For Example:

main.html file:

4条回答
  •  隐瞒了意图╮
    2020-11-27 07:55

    Angular uses the $sanitize on ng-include directives which strips out scripts. A better approach for templates is to create a controller for that template.

    It is better to use an individual controller for templates.

    In template.html

    In the LoginController you can use whatever code you want

    angular.module('myApp.controllers', []).
      controller('LoginController', [function() {
          alert('controller initialized');
      }])
    

提交回复
热议问题