目前我有一个Angular.js页面,允许搜索和显示结果.用户单击搜索结果,然后单击后退按钮.我希望再次显示搜索结果,但我无法确定如何触发搜索执行.这是详细信息:
如何在用户不必按"搜索按钮"的情况下再次执行搜索功能?如果它是jquery,那么我将在documentready函数中执行一个函数.我看不到Angular.js的等价物.
我正在使用一个名为 Gentelella 的模板,我正在尝试在其中实现 AngularJS。但是,我遇到了某个 Javascript 文件的问题。在该文件的末尾,$(document).ready调用了一个函数来初始化 Javascript 代码,从而对 HTML 代码进行一些更改。问题是该$(document).ready函数在 HTML 完全加载之前被调用得太早。
出现这个问题可能是因为我使用了 ngRoute,这会将模板 html 文件注入到 index.html 的 ng-view 中。发生这种情况时,DOM 可能已经在 AngularJS 注入模板 (=HTML) 之前宣布准备好文档。
所以基本上,一旦 AngularJS 注入模板,我只需要找到一种方法来调用 Javascript 文件中的一些代码。
我附上了一些代码来深入了解这个问题:
custom.min.js 的片段
$(document).ready(function () {
init_sparklines(), init_flot_chart(), init_sidebar(), init_wysiwyg(), init_InputMask(), ...
});
Run Code Online (Sandbox Code Playgroud)
main.js 的片段:
.config(function($routeProvider, $httpProvider) {
$routeProvider.when('/', {
templateUrl : 'dash.html',
controller : 'dash',
controllerAs: 'controller'
}).when('/login', {
templateUrl : 'login.html',
controller : 'navigation',
controllerAs: 'controller'
}).when('/plain_page', {
templateUrl : 'plain_page.html',
controller : 'dash', …Run Code Online (Sandbox Code Playgroud) 我正在学习AngularJS.我有一些文章标签,点击一个按钮,每个文章页面都显示没有任何页面刷新.这是一个页面的网站.我想要的是当文章ID"showSelector"被加载时我想调用myFunction(),在这个函数中我想显示一个警告.但警报没有显示.
我怎样才能做到这一点?
<article id="showSelector" class="panel" ng-controller="CinemaCtrl" onload="myFunction()">
<header>
<a ng-click="back()" class="icon fa-arrow-circle-left"></a><h2>Shows in {{getSelectedCinema()}}</h2>
</header>
<p>
These shows are played in our single room theatre. Select one to reserce a ticket for it.
</p>
<section>
<div class="row">
<div class="4u" ng-repeat="show in shows">
<div class="movieCard">
<a ng-click="selectShow(show)"></a>
<h3>{{show.nameOfShow}}</h3>
<h4>{{show.timeOfShow | date:'MMM d'}}</h4>
<h4>{{show.timeOfShow | date:'HH:mm'}}</h4>
<p>Free seats: {{show.reservations | freeSeatFilter}}</p>
</div>
</div>
</div>
</section>
<script>
function myFunction() {
alert("Page is loaded");
};
</script>
</article>
Run Code Online (Sandbox Code Playgroud)