Created
June 30, 2016 01:01
-
-
Save jsgao0/c526be55d375456998bd9576c03f7fea to your computer and use it in GitHub Desktop.
Difference between data-ng-model and ng-model in AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://www.concretepage.com/forum/thread?qid=462 | |
/* | |
This is for #1 and #2. | |
<div id="userInfo" data-user-name="Anson">Anson</div> | |
*/ | |
function nativeJS() { // #1 | |
var userInfo = document.getElementById("userInfo"); | |
var name = userInfo.getAttribute("data-user-name"); | |
// Anson | |
} | |
function usingJQ() { // #2 | |
var userInfo = $('div'); | |
var name = userInfo.data('user-name'); | |
// Anson | |
} | |
/* | |
This is for #3. | |
<input ng-model="firstName" /> | |
<input data-ng-model="lastName" /> | |
*/ | |
function usingNG() { // #3 | |
// firstName and lastName both work perfectly. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment