我是 angularjs 的菜鸟,我有一个问题。
我在我的网站中使用 prism.js 或highlights.js(相同的结果)。它可以在 index.html 中正常工作,但在我使用 ngRoute 加载的其他模板中不起作用。
我相信问题是 AngularJS 只是它再次渲染 html,并且当我加载 content-principal.html 时它不起作用。
索引.HTML
//<pre><code class="language-javascript">
colour syntax is ok
//</code></pre>
APP.JS
ionicEsApp.config(function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'templates/content-principal.html',
//controller: 'IonicEsController'
}).
内容-principal.html
//<pre><code class="language-javascript">
colour syntax is NO work
//</code></pre>
有什么解决办法吗?谢谢并抱歉我的英语:P。
SOLVED.
We need:
索引.html
prims.js 和 prism.css 来自http://prismjs.com/#basic-usage http://prismjs.com/#basic-usage
app.js
创建一个新指令(之前来自 .conf 非常重要)
var ionicEsApp = angular.module('ionicEsApp', [
'ngRoute',
'ngResource',
'ionicEsController'
]);
ionicEsApp.directive('ngPrism', [function() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
element.ready(function() {
Prism.highlightElement(element[0]);
});
}
}
}]);
ionicEsApp.config(function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'templates/content-principal.html',
//controller: 'IonicEsController'
}).
otherwise({
redirectTo: '/'
});
});
内容-principal.html
我们必须在代码标签中使用新指令。
<pre><code ng-prism class="language-javascript">
alert("Prims is ok");
</code></pre>
注意:html 有问题,我们需要用 < 替换
<pre><code class="language-markup">
<h1> Hello! </h1>
</code></pre>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)