angular.js - After defining directive in angular, is createElement necessary?
伊谢尔伦
伊谢尔伦 2017-05-15 16:57:17
0
5
577

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');
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(5)
滿天的星座

This is just for compatibility processing. IE8 cannot recognize custom elements, but those created with js can.

左手右手慢动作

document.createElementThis 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

如果你必需要用自定义元素标记,然后你必须采取以下步骤以确保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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template