我想创建一个动态指令。在这个指令中定义一个模板,其中包含一个输入元素。实际上该元素的
ng-model
必须是动态的,并使用控制器中的 $scope.name
。app.directive('helloWorld', function() {
return {
restrict: 'E',
replace: true,
scope: {
name: '@',
path:'@',
},
template: '<input\
type="text"\
name="{{name}}"\
ng-model="{{name}}"\
/>\,
link: function(scope, elem, attrs) {
},
controller:{
$scope.$watch($scope.name, function (newValue, oldValue) {
}
}
});