Angularjs Custom Directive ng-click not working

前端 未结 2 1914
予麋鹿
予麋鹿 2021-02-20 04:21

i\'ve created a custom directive in angularjs:

directives.directive(\'myTop\',function($compile) {
return {
    restrict: \'E\',
    templateUrl: \'views/header.         


        
2条回答
  •  忘掉有多难
    2021-02-20 04:55

    You'll need to add a link function to the directive definition for this to work. So basically,

    var app = angular.module("myApp", [])
    
    app.directive('myTop',function() {
    return {
        restrict: 'E',
        template: '',
        link: function (scope) {
            scope.clickFunc = function () {
                alert('Hello, world!');
            };
        }
    }
    })
    

    And the html:

    And here's the fiddle: http://jsfiddle.net/4otpd8ah/

提交回复
热议问题