`
yanzhihong23
  • 浏览: 57798 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Passing data into a directive

 
阅读更多

 

<div my-directive
    my-url="http://google.com"
    my-link-text="Click me to go to Google"></div>

 

angular.module('myApp', [])
    .directive('myDirective', function() {
        return {
            restrict: 'A',
            replace: true,
            scope: { // isolate scope
                myUrl: '@', // binding strategy
                myLinkText: '@' // binding strategy
            },
            template: '<a href="{{myUrl}}">' +
                '{{myLinkText}}</a>'
        }
    })

 

myUrl: '@'    expects    my-url

if we want to use another attribute value, eg. some-attr, we can change to

myUrl: '=someAttr'

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics