As shown in the following code, the directive layoutHeader is defined. According to my understanding, just quote <layout-header></layout-header>
directly in the html.
I would like to ask, here is
document.createElement('layout-header'); 有什么作用?是必须的吗?
The original code is as follows:
angular.module('app').directive('layoutHeader', function () {
return {
restrict: 'E',
scope: {},
templateUrl: 'components/layout/header.html',
controller: 'LayoutHeaderCtrl'
};
});
document.createElement('layout-header');
This is just for compatibility processing. IE8 cannot recognize custom elements, but those created with js can.
document.createElement
This is the js method provided by the browser. DOM can be generated using code.You can just quote it directly in html, there is no need to create it in code.
Just use <layoutHeader></layoutHeader> directly in the html code.
Is this a sample code?
In fact, it is just to create this element in js. It is the same as writing it directly in html.
= = I’m actually a little curious about what kind of introductory textbook this is. .
As xiaohe said, it is done for compatibility.
Reference: http://www.oschina.net/translate/angularjs-ie-compatibility?print