我有2个html页面和一个app.js
我的search-movie.html代码如下:
layout.addComponents(title, calculation);
和我的result-movie.html代码如下:
<!DOCTYPE html>
<html ng-app="adphorusWork">
<head lang="en">
<meta charset="UTF-8">
<title>Search Movie</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.min.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script src="app/app.js"></script>
</head>
<body ng-controller="searchMovieController">
<div class="navbar navbar-default navbar-fixed-top" style="margin-top: 20px;">
<div class="container-fluid">
<ul>
<li>
<a href="http://www.omdbapi.com/">OMDb Api</a>
</li>
</ul>
</div>
</div>
<div class="container" style="margin-top: 50px;">
<div class="bs-docs-section" id="">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2><a href="https://github.com/Cakmakk">My Github</a></h2>
</div>
<div class="bs-component">
<form class="well form-search" id="search-movie" onsubmit="return false;">
<fieldset>
<legend>Search Movie</legend>
</fieldset>
<div>
<label class="control-label" for="movie-name">Movie Name : </label>
<input type="text" id="movie-name" class="input-small" style="margin-left: 10px;">
<button id="btn-search-movie" type="button" class="btn-sm btn-primary" style="margin-left: 10px;" ng-click="searchMovie()">
<span class="glyphicon glyphicon-search"> Search</span>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
和我的app.js如下:
<!DOCTYPE html>
<html>
<head ng-app="adphorusWork">
<meta charset="UTF-8">
<title>Search Movie</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.min.js"></script>
<script src="app/app.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
</head>
<body ng-controller="resultMovieController">
<div class="navbar navbar-default navbar-fixed-top" style="margin-top: 20px;">
<div class="container-fluid">
<ul>
<li>
<a href="http://www.omdbapi.com/">OMDb Api</a>
</li>
</ul>
</div>
</div>
<div class="container" style="margin-top: 50px;">
<div class="bs-docs-section" id="">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2><a href="https://github.com/Cakmakk">My Github</a></h2>
</div>
<div class="bs-component">
<fieldset>
<legend>Result for Search Movie</legend>
</fieldset>
<div>
<button id="btn-result-movie" type="button" class="btn-sm btn-primary" style="margin-top: 40px;" ng-click="backtohome()">
<span class="glyphicon glyphicon-circle-arrow-left"> Home</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
我的搜索按钮正在运行(在search-movie.html中),但我的“主页”按钮无效(在result-movie.html中)
我在两个html页面中使用相同的ng-app。我想处理其他按钮(所以Home按钮)
我在哪里做错了?或者我该如何解决此错误?
答案 0 :(得分:2)
你需要使用Angular Ui路由器。并且@Lex是正确的,你没有遵循角度SPA framewrok。
这是一本很好的读物:https://github.com/angular-ui/ui-router
此链接可提供有关angular ui router https://scotch.io/tutorials/angular-routing-using-ui-router
的简要详细信息答案 1 :(得分:0)
你没有:
<script src="app/app.js"></script>
在您的result-movie.html页面中。但更重要的问题是,为什么要像这样构建它? Angular被设计为单页面应用程序(SPA)框架。你建立它的方式我觉得你最终会遇到很多问题。
答案 2 :(得分:0)
我注意到您没有加入result-movie.html
页面
<script src="app/app.js"></script>
至于最佳方法,您可以使用ngRoute
在控制器之间传递数据