【发布时间】:2019-01-11 23:40:12
【问题描述】:
我只是想澄清一些关于 Angular 的事情。一个项目交给了我,我注意到了一些关于实现它的方式,没有范围等。如果在 AngularJS 中实现什么或者你称这个结构是什么,谁能解释下面的代码?我理解逻辑,只是想知道我是否需要继续这种方式。关于范围与变量,您能说什么。或者如果这不是一个好的做法,请您纠正它。使用标准 JavaScript 是一种好习惯吗?为什么?
使用标准js
var vm = this;
vm.title = 'some title';
vm.saveData = function(){ ... } ;
return vm;
app.controller('testCtrl', function ($scope, $http, $controller, JFactory, Notification, $timeout, BtnLoad) {
var me = this;
me.current_page = "test page"
me.ladda = {}
me.base_url = BASE_URL
me.record = {
"is_applicant": true
}
me.create = function () {
var notify = true;
var url = BASE_URL + "/register/";
var params = me.record;
$http.post(url, params)
.then(function (response) {
if (response.status != "200") {
return
}
me.record = { "is_applicant": true, }
if (notify) { Notification.success(response.data) }
BtnLoad.spin.stop()
console.log("Endpoint :", url, (me.current_page) , response.status)
JFactory.closeModal('.modal')
})
.catch(function (response) {
BtnLoad.spin.stop()
if (notify) { Notification.error(response.data) }
})
}
【问题讨论】:
标签: javascript angularjs architecture structure