How to call a function in “ng-src”

后端 未结 3 1213
借酒劲吻你
借酒劲吻你 2020-12-24 00:59

I need to be able to call a function in order to run code to dynamically retrieve the source of an image. The following code snippet shows an example of what I want:

3条回答
  •  难免孤独
    2020-12-24 01:16

    Right, got there in the end:

    JavaScript:

     angular.module('MyApp', [])
        .controller('Ctrl2', function($scope) {
        })
        .directive('mySrc', function() {
            return {
            restrict: 'A',
            link: function ( scope, elem, attrs ) {
                 //replace test with whatever myFunction() does
                 elem.attr('src', 'test1');
            }
          };
        });
    

    HTML:

    Fiddle

提交回复
热议问题