我正在构建一个简单的 angularjs 应用程序,我正在尝试在不刷新页面的情况下实现登录。
我在做什么
在初始化时,ng-include 加载 /set/save。/set/save 包含<a fblogin>Login with Facebook</a>
在其中。因此,当单击指令打开一个窗口时,当窗口关闭时,它应该更改 ng-include 的 src。
问题
当在 ng-include 中使用该指令时( ng-include src 在 init 上有默认值),什么也没有发生(控制台中没有错误,只是什么都没有),但是当我将指令放在 ng-include 之外时,它工作正常(见下面的 HTML 代码)
HTML:
<div id="set-creator" ng-controller="SetCtrl">
........
<div id="saveModal" class="reveal-modal" data-reveal>
<a href fblogin>testCase</a>
// ^this is working
//but if the directive is inside ng-include, it's not working
<ng-include src="saveTemplate"></ng-include>
<a class="close-reveal-modal">×</a>
</div>
</div>
指示:
App.directive('fblogin', function() {
return {
transclude: false,
link: function(scope, element, attrs) {
element.click(function() {
var win = window.open("/auth/facebook", 'popUpWindow', 'centerscreen=true');
var intervalID = setInterval(function() {
if (win.closed) {
scope.saveTemplate = '/set/continue';
scope.$apply();
clearInterval(intervalID);
}
}, 100);
});
}
};
});
控制器:
App.controller("SetCtrl", ["$scope", "SetHolder",
function($scope, SetHolder) {
$scope.saveTemplate = '/set/save';
$scope.test = "loaded";
}
]);
和/设置/保存
You need to be logged in order to save the set.
<br />
<a fblogin>Login with Facebook</a>