【发布时间】:2015-04-21 13:27:27
【问题描述】:
我正在尝试从其他 javascript 文件调用我的jointController 中的一个函数。
var app1 = angular.module('jointApp',[]);
var createStateBox = function(label,color){
var state = new uml.State({
position: {x: 0, y: 0},
size: {width: 200, height: 100},
name: "<<"+label+">>",
events: [label+" box"],
attrs:{rect:{fill:color},path:{"stroke-width":0}}
});
app1.controller('jointController', function($scope) {
$scope.setDecision(state);
alert("This is reached");
});
paper.model.addCell(state);
}
这是jointMod.js中包含jointController的代码
var app = angular.module('jointApp', []);
function JointController($scope, $http, $filter) {
$scope.list = [];
$scope.newMsg = 'hello';
$scope.newDecision;
$scope.setMsg = function(msg) {
$scope.newMsg = msg;
}
$scope.sendPost = function() {
var data = $.param({
json: JSON.stringify({
msg: $scope.newMsg
})
});
$scope.setDecision = function(decision){
$scope.newDecision = decision;
alert("one two one two")
console.log(decision);
}
$http({
method: 'POST',
url: 'http://213.65.171.121:3000/decision',
data: $scope.newMsg,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
str.push(encodeURIComponent("action") + "=" + encodeURIComponent(obj));
return str.join("&");
}
}).success(function(data, status, header, config) {
$scope.list.push(status);
}).error(function(data, status, header, config) {
$scope.list.push(status);
});
};
};
我在那里有警报和控制台登录,以确保他们是否可以到达,但他们没有响应。
【问题讨论】:
-
你想将第一个 $scope 用于第二个控制器吗?
-
好吧,现在我明白我做错了什么,但是如何在第一个代码中使用第二个控制器的 $scope?(我只想使用第二个控制器)
-
我想我需要更新我的问题:我知道我没有以正确的方式创建控制器,并且在第一部分代码中我犯了一个错误来创建不同的模块和控制器。但我想问的问题是。是否可以从其他 javascript 文件(不是 html)调用位于 javascript 文件中的控制器的函数,如果可能,您是如何做到的
标签: javascript angularjs jointjs