javascript命名空间中的角度控制器

时间:2015-04-21 21:51:44

标签: asp.net-mvc angularjs

我是Angular的新手,我开发了以下代码:

(function (Field, $, undefined) {

    Field.GetDataSourceList = function () {

        $http.post(Field.UrlGetDataSourceList, {}).
        success(function (data, status, headers, config) {
            // this callback will be called asynchronously
            // when the response is available
        }).
        error(function (data, status, headers, config) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
        });
    };

    Field.GetFieldTypeList = function () {

        $http.post(Field.UrlGetFieldTypeList, {}).
        success(function (data, status, headers, config) {
            // this callback will be called asynchronously
            // when the response is available
        }).
        error(function (data, status, headers, config) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
        });
    };

    Field.TheField = function ($scope) {

        $scope.Model = function () {
            $scope.DataSourceSecected = {};
            $scope.DataSourceList = {};

            $scope.Id = "";
            $scope.Name = "";

            $scope.FieldTypeSelected = {};
            $scope.FieldTypeList = {};

            $scope.SecctionId = "";
            $scope.Order = "";
        };

        $scope.Add = function () {
            $scope.Model.latestValue = $scope.Model.newValue;
            $scope.Model.newValue = "";
        };
    };

    Field.SetUrl = function (data) {

        Field.UrlGetDataSourceList = data.UrlGetDataSourceList;
        Field.UrlGetFieldTypeList = data.UrlGetDataSourceList;
    };

    Field.Init = function () {

        var theField = new Field.TheField();

        theField.$inject = ["$scope"];

        theField.Model.DataSourceList = Field.GetDataSourceList;
        theField.Model.FieldTypeList = Field.GetFieldTypeList;
    };

}(window.Field = window.Field || {}, jQuery));

在我的页面中,我需要调用这样的函数:

<script type="text/javascript">

        $(document).ready(function() {

            Field.SetUrl({

                UrlGetDataSourceList: "@Url.Action("GetDataSourceList", "DataSource")",
                UrlGetFieldTypeList: "@Url.Action("GetFieldTypeList", "Field")"
            });

            Field.Init();

        });

    </script>

但我一直在网上调查,我认为Angular有点不同:

我想在我的角度控制器上调用一些函数,比如说:

var theField = new Field.TheField();
theField.$inject = ["$scope"];

theField.Model.DataSourceList = Field.GetDataSourceList;
theField.Model.FieldTypeList = Field.GetFieldTypeList;

但不起作用......帮助......

我这样做是因为我喜欢我的项目结构很好......

PD:我来自Knockout ......

0 个答案:

没有答案