//注意:这边定义的toString 引用时候就是to-string(大写字母变为-加上小写字母)
app.directive("toString", function () {
return {
restrict: "A",
require: "ngModel",
link: function (scope, elem, attr, ngModelCtr) {
ngModelCtr.$formatters.push(function (viewValue) {
if (typeof viewValue == "undefined") {
return '';
} else {
var val1 = viewValue.toString();
if (val1.indexOf('.') != -1) {
return viewValue.toString().split('.')[0]
} else {
return viewValue.toString();
}
}
})
}
}
});
//引用的地方
<input type="radio" name="" value="" ng-model="" to-string>
Angularjs前台转换成string类型
最新推荐文章于 2023-09-19 15:18:31 发布