2

I am creating an angular.js application. I have written a html page and wants to put it under div using directive

 <div data-(<directive-name)>
</div>

DxPDictionary.directive('import', [function () {
        return {
            restrict: 'A',
            templateUrl: 'template/Import.html',
            scope: false,
        }

It's not working, is this approch is right or should use another way to achieve this

2
  • please your code of your directive Commented Jul 6, 2015 at 4:29
  • I did Please check it once again Commented Jul 6, 2015 at 4:52

3 Answers 3

2
<body ng-controller="userCtrl">

    <div class="container">
        <div ng-include="'myUsersList.html'"></div>
        <div ng-include="'myUsersForm.html'"></div>
    </div>

</body>
Sign up to request clarification or add additional context in comments.

Comments

0

use like this.

 <div data-directive-name>
</div>

DxPDictionary.directive('dataDirectiveName', [function () {
        return {
            restrict: 'A',
            templateUrl: 'template/Import.html',
            scope: false,
        }

your directive name dataDirectiveName in directive definition in camel case format and directive name data-directive-name on DOM should match.

You can use ng-include if you are not creating reusable components using directive and want use is as only html of the page.

Comments

0

There is already a directive for this purpose. You do not need to create your own.

https://docs.angularjs.org/api/ng/directive/ngBindHtml

Ashley's answer is good if you keep your html in a file. If you dynamically generate your html, you can use ng-bind-html directive.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.