目前我有两个控制器,一个是用户输入值的表单,另一个是基于api搜索的图形。我需要根据来自第一个控制器的输入刷新或重新运行第二个控制器。我几乎可以肯定,这是一个糟糕的设计,但我还没有找到理想的方法去做。
HTML代码:
<html>
<body>
<!-- this is the graph generator-->
<div ng-controller="GraphAppCtrl"></div>
<!-- this is th form submittal section-->
<div ng-controller="FormCtrl" id="FormCtrl">
<form novalidate class="simple-form">
Name: <input type="text" ng-model="tech"/><br />
<button ng-click="submit(tech)">Submit</button>
</form>
</div>
</body>
</html>角码:
var app = angular.module('testApp', []);
app.controller('FormCtrl', function ($scope) {
$scope.submit = function(tech){
// Need to be able to call the function that generates graph and pass it the tech value
}
}
app.controller('GraphAppCtrl', function ($scope) {
//here I do a bunch of stuff to generate graph, like http request from third party api etc.
}现在发生了什么,因为我在我的index.html页面中引用了图形控制器,它第一次根据默认参数呈现,但是我需要它根据提交来呈现。
我看过指令,并在这个question中尝试了答案,但它似乎更像是在控制器之间传递数据的解决方案,而不是我想要做的事情。
发布于 2014-11-19 20:45:28
https://stackoverflow.com/questions/27026340
复制相似问题