我想将范围从指令更新到控制器

时间:2015-12-24 06:18:53

标签: angularjs angularjs-directive

我想将范围从指令更新到控制器

我的控制器

$scope.getBusinessViewDetails = function () {
      if ($scope.newRecord) {
          return;
      }
      dataFactory.get("/BusinessView/GetBusinessViewById?applicationId=" + $scope.currentAppId + "&viewId=" + $scope.$stateParams.viewId + "&objectId=" + $scope.$stateParams.formId)
      .then(function (result) {
          $scope.businessview = result.data.data;
          $scope.objectPartialShow = "search";
          $scope.businessview.objectId = $scope.businessview.object_id;
          $scope.changeSetInfo = $scope.businessview;
          var data = JSON.parse($scope.businessview.json_meta_data);
          data[0].dynamicFields = [];
          $scope.tree = data;
          $scope.objectColumnTag = $scope.tree[0].selectColumns;
          if ($stateParams.version == "true") {
              $scope.viewstate = $state.current.name;
              $scope.changeSetInfo = $scope.businessview;

              $scope.viewid = $scope.$stateParams.viewId;
              $scope.formid = $scope.$stateParams.formId;
              $scope.appid = $scope.currentAppId;
              $scope.version = true;
          }
          else {
              $scope.version = false;
          }
      });

  }
$scope.getBusinessViewDetails();

我的指示是

.directive('pagesliderdirective', ['$state','dataFactory',
    function ($state, dataFactory) {
        /**          
        * @name directive.checkbox
        * @description checkbox element
        * @param {object} field, required  and options
        * @param {object} value, defaul value of the field, could be null             
        * @param {string} inputClass, optional, optional css class            
        * @returns {object} directive
        */
        return {
            restrict: 'A',
            replace: true,
            //scope:false,
            scope: {
                ismenu: "=",
                versions: "=",
                viewstate: "=",
                changeset: "=",
                appid: "=",
                viewid: "=",
                formid: "=",
                businessview:'='
            },
            templateUrl: '../Scripts/app/shared/directives/pagesliderdirective/partials/pagesliderdirective.html',
            link: function (scope) {
                debugger;
                scope.Versions = function () {

                    dataFactory.get("/BusinessView/GetBusinessViewVersionsById?applicationId=" + scope.appid + "&viewId=" + scope.viewid + "&objectId=" + scope.formid)
                   .then(function (result) {
                       scope.versions = result.data.data;
                   });
                }

                scope.toggleClick = function () {
                    scope.ismenu = !scope.ismenu;
                };
                scope.versionIndex = 0;
                scope.versionSelected = function (item, version) {
                    scope.versionIndex = item;
                    scope.businessview = version;
                    scope.changeSetInfo = "text123";
                    debugger;
                    //scope.getBusinessViewDetails();
                    //$state.go(scope.viewstate, { version: true, formId: version.object_id, viewId: version.id })
                };
                scope.Versions();
            }
        }
    }]);

Html Page

  <div pagesliderdirective ismenu="isMenu" versions="versionsList" viewstate="viewstate" changeset="changeSetInfo" appid="appid" viewid="viewid" formid="formid" businessview="businessview"></div>

在指令中我正在使用此

 scope.versionSelected = function (item, version) {
                    scope.versionIndex = item;
                    `scope.businessview` = version;
                    scope.changeSetInfo = "text123";
                    debugger;
                };

在我的控制器中我有$ scope.businessview,我正在将该值更新为指令,而scope.businessview = version;未在我的控制器中更新。

请为此我需要解决方案

0 个答案:

没有答案