angular directive

HTML:

        <input ng-model="outUrl" />

        <div my-directive my-url="outUrl" my-name="baidu"></div>


app.js:

var app = angular.module('app',['app.services', 'app.controllers','app.directives']);

var services = angular.module('app.services', []);

var controllers = angular.module('app.controllers', []);

var directives = angular.module('app.directives', []);


directives.js

directives.directive('myDirective',function(){

    return {

        restrict:'A',

        repalce:true,        

        scope:{

            myUrl:'=myUrl',//双向绑定

            myName:'@myName '//单向绑定

        },

        template:'<input ng-model="myUrl"/><a href="{{myUrl}}">{{myName}}</a>'

    }

});


你可能感兴趣的:(angular directive)