use*_*584 5 javascript angularjs total.js
我有一些AngularJS东西,它包含一堆数组和数据.用户上传文件后,文件将被解析并保存到具有不同数组的范围中.但是,在完成所有这些并且文件保留在作用域中之后,我尝试更新innerHTML,但AngularJS代码不起作用.我ng-repeat用来创建一个基于数组的表,但它仍然是一个单元格,内容看起来像{{column}}等.
我不得不使用指令和模板极端困难,因为我的index.html说app和module等,是不确定的,当我做一些事情,如app.directive(...
我的index.html文件的重要部分包括:
<html ng-app>
... //once a file is uploaded, total.js is called;
//this was so the app didn't try to run before a file was uploaded
<div id="someStuff">This will become a table once a file is uploaded</div>
Run Code Online (Sandbox Code Playgroud)
这是我在total.js中设置范围的一个简单示例:
function sheet($rootScope, $parse){
$rootScope.stuff = text;
//text is a variable that contains the file's contents as a string
};
document.getElementById('someStuff').innerHTML="<div ng-controller='sheet'>{{stuff}}</div>";
Run Code Online (Sandbox Code Playgroud)
HTML更改但不打印文件的内容,而是仅打印{{stuff}}.我如何让innerHTML理解它包含AngularJS,最好不使用partial或指令,除非你能彻底解释我输入它的位置及其语法.
编辑1: 我尝试使用$ compile但它被标记为未定义.我查看了这个以找出编译问题,但我不理解rtcherry的语法,以及我应该如何将它应用于我自己的代码.
编辑2: 当我包含它时,我仍然收到$ compile undefined错误:
function sheet($rootScope, $parse, $compile){...};
document.getElementById('someStuff').innerHTML=$compile("<div ng-controller='sheet'>
{{stuff}}</div>")(scope);
Run Code Online (Sandbox Code Playgroud)
编辑3: 虽然itcouldevenbeaboat的评论非常无益,但我决定我应该向你展示我尝试这样做的指令.
我将此代码包含在我的工作表函数中:
var app = angular.module('App', []);
app.directive('spreadsheeet', function($compile){
return{
templateUrl: innerHTML.html
}
});
Run Code Online (Sandbox Code Playgroud)
在innerHTML包含的地方<div ng-controller='sheet'>{{stuff}}</div>和index.html上我已经包含了<div spreadsheet></div>
有了这个,我没有收到任何错误,但文本没有显示,也没有显示{{stuff}}文件的内容.即使我做一些简单的事情,比如提供template: "<h2>Hello!</h2>"而不是一个templateUrl,我也无法Hello!进行打印.
这个对我有用
document.getElementById('someStuff').innerHTML = "<div ng-controller='sheet'>{{stuff}}</div>";
$compile( document.getElementById('someStuff') )($scope);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26615 次 |
| 最近记录: |