Angularjs中數(shù)據(jù)綁定的實(shí)例詳解
這是一個(gè)最簡(jiǎn)單的angularjs的例子,關(guān)于數(shù)據(jù)綁定的,大家可以執(zhí)行一下,看看效果
<html ng-app><head><title>angularjs-include</title><script type="text/javascript" src="js/angular/angular.min.js"></script></head><body><input type="text" ng-model="name" value="" /><br /><div>Hello,{{name}}</div></body></html>
關(guān)于數(shù)據(jù)雙向綁定,有時(shí)候不需要實(shí)時(shí)同步,比如當(dāng)輸入框失去焦點(diǎn)的時(shí)候才去更新div里面的內(nèi)容,這里可以用上ng-model-options屬性來(lái)解決,將上面的代碼稍做修改:
<html ng-app><head><title>angularjs-include</title><script type="text/javascript" src="js/angular/angular.min.js"></script></head><body><input type="text" ng-model="name" value="" ng-model-options="{ updateOn: 'blur' }" /><br /><div>Hello,{{name}}</div></body></html>或者改為每隔1秒來(lái)更新:
<html ng-app><head><title>angularjs-include</title><script type="text/javascript" src="js/angular/angular.min.js"></script></head><body><input type="text" ng-model="name" value="" ng-model-options="{ debounce: {default:1000} }" /><br /><div>Hello,{{name}}</div></body></html>如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,大家共同進(jìn)步,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選