AngularJS進階 十六 髒值檢查
阿新 • • 發佈:2019-01-04
髒值檢查
注:請點選此處進行充電!需求
在專案開發過程中,需要對藥店資訊進行更改。如下圖所示。現在的需求是:當藥店資訊沒有發生變化時,點選“更新資訊”按鈕,提示“藥店資訊未做任何更改”。
實現
可以利用angualr的髒值檢查機制解決。
由於對angular的髒值檢測機制不是很瞭解,貌似也不太好學習。就考慮使用別的方法,也可以使用ng-change內建指令,通過控制業務邏輯實現。Demo如下:
View檢視:
<input ng-model="addr_y" id="addr_y" type="text" ng-change="textChange(addr_y)" />
Controller控制器:
$scope.doUpdate = function(){
var change = instance.change;
if(!$scope.shopname){
alert("藥店名稱不能為空,請輸入...");
return;
}
................................
if(!$scope.addr_y){
alert("銀行緯度不能為空,請輸入...");
return ;
}
$scope.textChange = function(val){
// alert('變化了');
instance.change = true;
}
//alert(change);
if(!change){
alert("藥店資訊未做任何更改");
}else{
appCallServer($http,"G016",{"mangid":localStorage.mangid,
"shopid":"S"+$scope.phone,
...............
"addr_x":$scope.addr_x,
"addr_y":$scope.addr_y
},
function (data){
//success function
alert("儲存藥店資訊成功");
instance.change = false;
//window.location="index.html";
});
}
};
效果
當資訊未做修改時
當資訊修改時
附:angular架構圖
再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智慧的隊伍中來!https://www.cnblogs.com/captainbed