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');
滿天的星座2017-05-15 16:59:17
This is just for compatibility processing. IE8 cannot recognize custom elements, but those created with js can.
ringa_lee2017-05-15 16:59:17
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.
仅有的幸福2017-05-15 16:59:17
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. .
巴扎黑2017-05-15 16:59:17
As xiaohe said, it is done for compatibility.
Reference: http://www.oschina.net/translate/angularjs-ie-compatibility?print
如果你必需要用自定义元素标记,然后你必须采取以下步骤以确保IE8及之前版本都能用:
<!doctype html>
<html xmlns:ng="http://angularjs.org" id="ng-app" ng-app="optionalModuleName">
<head>
<!--[if lte IE 8]>
<script>
document.createElement('ng-include');
document.createElement('ng-pluralize');
document.createElement('ng-view');
// Optionally these for CSS
document.createElement('ng:include');
document.createElement('ng:pluralize');
document.createElement('ng:view');
</script>
<![endif]-->
</head>
<body>
</body>
</html>