Note that there are some explanatory texts on larger screens.

plurals
  1. POBind Angularjs to newly created html element dynamically
    primarykey
    data
    text
    <p>I have a tab page with multiple tabs that once clicked on call a service to return some data. Some of that data returns html forms and are very random. I want to collect those values that are entered and send the data via a service back to the server. The problem I have is that I can't get the data from the input elements in the html I'm creating dynamically.</p> <p>I've created a <a href="http://plnkr.co/edit/PS6tN1KLr1Anv4SN54HY?p=preview">Plunker</a> to show what the issue is. Note that the html value can change at any time so hard-coding the html won't work. Here the code from the plunker, but please look at the plunker for the best view of whats going on.</p> <p><strong>app.js</strong></p> <pre><code>var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope, $sce, $compile) { $scope.name = 'World'; $scope.html = ""; $scope.htmlElement = function(){ var html = "&lt;input type='text' ng-model='html'&gt;&lt;/input&gt;"; return $sce.trustAsHtml(html); } }); </code></pre> <p><strong>index.html</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html ng-app="plunker"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;AngularJS Plunker&lt;/title&gt; &lt;script&gt;document.write('&lt;base href="' + document.location + '" /&gt;');&lt;/script&gt; &lt;link rel="stylesheet" href="style.css" /&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js"&gt;&lt;/script&gt; &lt;script src="app.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body ng-controller="MainCtrl"&gt; &lt;p&gt;Hello {{name}}!&lt;/p&gt; &lt;div ng-bind-html="htmlElement()"&gt;&lt;/div&gt; {{html}} &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload