html
===
<a target="中獎發票" detail ng-model="data.id">詳細</a>
javascript
===
.directive("detail", ['$http', function ($http) {
return {
require: "ngModel",
link: function (scope, element, attributes, ngModel) {
element.on('click', function (event) {
$http.post('@Url.Action("詳細資料")', { id: ngModel.$viewValue })
.then(function (result) {
element.attr('href', result.data);
}).catch(function (data) {
console.log(data);
if (data.statusText != '') alert(data.statusText);
else alert('發生錯誤,請重新整理頁面後再試一次');
});
});
}
}
}])