我只是想澄清一些有关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) }
            })
    }

最佳答案

我将其称为:“遵循John Papa Angular 1样式指南”。

他建议在$scope语法上使用此语法。

如果整个应用程序都是按照他的指南编写的,那么我强烈建议您阅读他的指南。

如果不是,我仍然强烈建议您阅读他的指南,因为即使您不同意本指南中的所有内容,它仍然可以为Angular JS提供一些非常有用的指南。

https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md

10-07 19:59
查看更多