我做了一个自定义指令来将句子更改为编辑框,但是当没有输入时它会如何跳回?
这是我的HTML:
<name ng-hide="!custom1" my-text="name" placeholder="jhkiii" class="des"</name>
<a href="#" ng-click="custom1=!custom1" ng-hide="custom1">
Select to add a description 1<i class="fa fa-pencil"></i>
</a><br>
<name ng-hide="!custom2" my-text="desc" placeholder="asdfasd" class="des">
</name>
<a href="#" ng-click="custom2=!custom2" ng-hide="custom2">
Select to add a description 2<i class="fa fa-pencil"></i> </a>
这是我的angularjs代码:
.directive("name",function(){
return{
restrict:"E",
/*scope:{
text:'=placeholder'
},*/
scope:{
},
link: function (scope, element, attrs) {
scope.myClass=attrs['class'];
console.log(scope.myClass);
scope.placeholder=attrs['placeholder'];
},
template:'<input type="text" autofocus placeholder="{{placeholder}}" class="{{myClass}}"/>',
controller: function($scope){
/*$scope.$watch("name", function(newValue, oldValue) {
if (newValue.length <= 0) {
alert("nothing change");
}
});*/
}
}
这是输出:
Select to add a description 1
Select to add a description 2
单击链接后,它将变为输入框,但是当没有输入时,它是丢失焦点,它将跳回到“选择添加描述1”此链接。我想我应该使用$ watch,但不知道如何,或者你有任何想法,请帮助我。谢谢!