我已经为我的应用程序创建了一个指令,在下面的问题中提到了 如何使用AngularJS或Javascript提供下载文件?指令代码如下所示
appModule.directive('fileDownload', function ($compile) {
var fd = {
restrict: 'A',
link: function (scope, iElement, iAttrs) {
scope.$on("downloadFile", function (e, url) {
var iFrame = iElement.find("iframe");
if (!(iFrame && iFrame.length > 0)) {
iFrame = $("<iframe style='position:fixed;display:none;top:-1px;left:-1px;'/>");
iElement.append(iFrame);
}
iFrame.attr("src", url);
});
}
};
return fd;
});
Run Code Online (Sandbox Code Playgroud)
这里使用范围.$ on,当我通过$ scope.$ emit或$ scope.$ broadcast调用此事件时,它不起作用.我的控制器代码如下所示
function reportsController($scope, $http) {
var self = this;
$scope.$broadcast("downloadFile", 'http://google.com');
$scope.$emit("downloadFile", 'http://google.com');
}
Run Code Online (Sandbox Code Playgroud)
我的html文件如下
<div ng-controller="reportsController" id="repctrl">
<a file-download></a>
</div>
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
@Edit:在编译阶段添加了subscribe($ on),以避免在控制器中使用$ timeout.在这里 …
我创建了一个像下面的xml
<Request>
<RequestType>Logon</RequestType>
<MobileId>23424</MobileId>
<Password>123456Gg</Password>
</Request>
Run Code Online (Sandbox Code Playgroud)
我的xsd文件就像下面的代码
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Request" type="RequestType"/>
<xsd:complexType name="RequestType">
<xsd:sequence>
<xsd:element name="RequestType">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Logon"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="MobileId" >
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="0" />
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Password">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="0"/>
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
我使用PHP'S DOMDocument的schemaValidate函数来验证xml对xsd,并给出以下错误
Fatal Error 4: Start tag expected, '<' not found on line 5
Error 1872: The document has …Run Code Online (Sandbox Code Playgroud)