Skip to content

Instantly share code, notes, and snippets.

@jsgao0
Created June 30, 2016 01:01
Show Gist options
  • Save jsgao0/c526be55d375456998bd9576c03f7fea to your computer and use it in GitHub Desktop.
Save jsgao0/c526be55d375456998bd9576c03f7fea to your computer and use it in GitHub Desktop.
Difference between data-ng-model and ng-model in AngularJS
// 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