GVKun编程网logo

angularjs – Angular-ui State – 多个视图没有看到我的解析数据(angular 多页面)

26

关于angularjs–Angular-uiState–多个视图没有看到我的解析数据和angular多页面的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angularjs–Angular

关于angularjs – Angular-ui State – 多个视图没有看到我的解析数据angular 多页面的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?、angularjs – Angular Bootstrap Dropdown在Angular Fullstack中不起作用、angularjs – Angular JS – 将ng-click $index值传递给控制器函数,然后返回另一个视图、angularjs – Angular UI Bootstrap datepicker,视图更改时的回调等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

angularjs – Angular-ui State – 多个视图没有看到我的解析数据(angular 多页面)

angularjs – Angular-ui State – 多个视图没有看到我的解析数据(angular 多页面)

出于某种原因,当使用多个命名视图(angular-ui ui-router)时,我的resolvedData没有被控制器看到.有人遇到过这个问题吗?

$stateProvider
    .state('page',{
           abstract: true,templateUrl: ...,controller: abstractController
    })
    .state('page.index',url: '/page',resolve : {
               resolvedData: function(CONSTANTS){ return CONSTANTS.data;}
           },views: {
               home: {templateUrl: ...,controller: function(resolvedData){
                        ....
                      }
               },list: {templateUrl: ...,edit: {templateUrl: ...,controller: function(resolvedData){
                        ....
                      }
               }
           }
     )

它给我的错误是:错误:[$injector:unpr]未知提供者:resolvedDataProvider< - resolvedData.它有点有趣,因为它只发生在一个视图中而不是其他视图中.

解决方法

我创建了 small working example,显示你的东西应该工作

这将是常数:

.factory('CONSTANTS',function() {
    return { data: { name :  "some name",number : "some number"} };
})

同样(只是明确注释DI)状态def:

// States
  $stateProvider
    .state('page',{
      abstract: true,template: '<div>' 
       + '<div ui-view="home"></div>' 
       + '<div ui-view="list"></div></div>',controller: 'abstractController'
    })
    .state('page.index',{
      url: '/page',resolve: {
        resolvedData: ['CONSTANTS',function(CONSTANTS) {
            return CONSTANTS.data;
          }
        ]
      },views: {
        home: {
          templateUrl: 'tpl.html',controller: ['resolvedData','$scope',function(resolvedData,$scope) {
              console.log(resolvedData);
              $scope.resolvedData = resolvedData;
            }
          ],},list: {
          template: '<div>list view</div>'
        }
      }
    })

因此,上面使用的决议草案正在起作用.这是正确的方法……解析函数提供了一些服务…并返回其属性数据.

检查所有here

angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?

angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?

在Angular 1和ui-router中,我使用状态参数来将数据从一个状态传递到另一个状态(不使用URL参数).在Angular 2中有可能吗?

Router,RouteParams,RouterLink和RouteData似乎没有处理这个问题,例如我想将用户对象从一个状态传递到另一个状态

<a ui-sref="home({user: myCtrl.user})">

这在Angular 2中似乎不可能.

解决方法

如果你正在使用Angular 2路由器,你可以通过@RouteParams传递状态,例如,

<a [routerLink]="['/ProductDetail',{id: 1234}]">Product Details</a>

在这种情况下,id是你的状态,它可以是任何对象,例如:

<a [routerLink]="['/ProductDetail',myStateObject]">Product Details</a>

另一方面,Angular 2有一种机制,可以使用绑定传递参数到组件的@input()参数,但这只能在同一路径中使用.

angularjs – Angular Bootstrap Dropdown在Angular Fullstack中不起作用

我已直接从 Angular Bootstrap UI Plunkr复制代码

我使用空白的Angular FullStack(Mean)模板来构建应用程序.

当我使用Angular Bootstrap uib-dropdown中的代码时,它最终格式化不正确并且不起作用,所有其他角度引导程序组件似乎都能正常工作

<!-- Single button -->
<divuib-dropdown is-open="status.isopen">
  <button id="single-button" type="button"uib-dropdown-toggle ng-disabled="disabled">
    Button dropdown <span></span>
  </button>
  <ulrole="menu" aria-labelledby="single-button">
    <li role="menuitem"><a href="#">Action</a></li>
    <li role="menuitem"><a href="#">Another action</a></li>
    <li role="menuitem"><a href="#">Something else here</a></li>
    <li></li>
    <li role="menuitem"><a href="#">Separated link</a></li>
  </ul>
</div>

在bower.json中升级Angular UI:
"angular-bootstrap": "~0.14.3",

然后运行:

bower install

angularjs – Angular JS – 将ng-click $index值传递给控制器函数,然后返回另一个视图

angularjs – Angular JS – 将ng-click $index值传递给控制器函数,然后返回另一个视图

我将ng-click $index值传递给我的控制器,然后使用它在ng-repeat中的值来表示我的数据,但得到的错误表明“ReferenceError:myChoice未定义”

我的观点(months.html)有一个所有月份的列表,选中后,它会将值传递给控制器​​.

<ion-list ng-repeat="time in times.months" ng-click="getMonthId($index)">
  <ion-itemhref="#/dmtimes">{{ time.monthId }} - {{ time.MonthName }</ion-item>
</ion-list>

视图输出显示:

1 - Jan
2 - Feb 
3 - Mar
etc

我的控制器有以下提取代码:

.controller('dailyMeetingTimesCtrl',function($scope,MeetingNames,$ionicLoading,$firebase,$firebaseArray) {

  $scope.getMonthId = function (monthId) {
    alert("you selected: " + monthId); // this works fine.
    $scope.myChoice = monthId; // ReferenceError: myChoice is not defined

    console.log(myChoice);
  }
})

在我的第二个视图(displayMeetingTimes.html)中,我想显示所选月份的会议详细信息,时间等.代码如下:

<ion-view title="Daily Meeting Times">
  <ion-content ng-controller="dailyMeetingTimesCtrl"overflow-scroll="true" padding="true">
    <ion-list>

      <ion-item ng-repeat="time in times.months(myChoice).days">
        <span>{{myChoice}}</span>
        Meeting Name:   {{ time.meetingName }}<br />
        Star Time:  {{ time.startTime }}<br />
        Finish Time:    {{ time.finishTime }}<br />
      </ion-item>         
    </ion-list>

  </ion-content>
</ion-view>

当我运行应用程序时,’myChoice’的值没有传递到第二个视图,因此错误“ReferenceError:myChoice未定义”

请告诉我哪里出错了?谢谢.

解决方法

如果要使用ng-repeat传递$index,则需要指定它.所以你的HTML应该如下:

<ion-list ng-repeat="time in times.months track by $index" ng-click="getMonthId($index)">
  <ion-itemhref="#/dmtimes">{{ time.monthId }} - {{ time.MonthName }
  </ion-item>
</ion-list>

其次,你得到ReferenceError的原因:myChoice没有被定义,因为你从未初始化一个名为myChoice的变量.但是你有一个名为$scope.myChoice的变量.
因此,您应该执行以下操作以在控制台中显示变量:

console.log($scope.myChoice);

angularjs – Angular UI Bootstrap datepicker,视图更改时的回调

angularjs – Angular UI Bootstrap datepicker,视图更改时的回调

我使用Angular UI Bootstrap,这两个版本都是最新版本.

我希望在我的视图发生变化时进行回调,即当我从5月切换到6月时.我需要这个,因为以下情况:

我的日期选择器使用customClass函数显示可用和不可用的日期.
我获取当前月份的所有可用性,但是当我单击下一个或上一个时,我没有任何回调来获取新的可用性.

另外,我不想要一次42次异步调用(每个类一次)因为你在de datepicker中也会遇到很多时间问题.
我希望有人知道实现这一目标的方法,我现在已经很长时间寻找解决方案了.

我的HTML:

<div>
      <spanng-click="vm.OpenDatepicker($event,'1')"><i></i></span>
      <input type="text"datepicker-options="dpOptions" readonlyuib-datepicker-popup="dd-MMMM-yyyy" min-date="minDate" show-weeks="true" ng-model="selectedDate"
             is-open="vm.$scope.datepickers[1]" show-button-bar="false" ng-click="vm.OpenDatepicker($event,'1')" />
</div>

在$scope.dpOptions(DatePicker Options)中,我定义了自定义类需要的内容:

$scope.dpOptions.customClass= function (data) {
//Here are my availabilities of the first month fetched
//When I change the month in my view,I first want to have the other availabilities 
//so I can return the new red/green classes
};
我的同事找到了一个使用角度$provide.decorator函数的解决方案!
这将为任何现有指令添加一些附加功能.
$provide.decorator('uibDatepickerDirective',function ($delegate) {
        var directive = $delegate[0];
        var directiveCompile = directive.compile;

        directive.compile = function () {
            var link = directiveCompile.apply(this,arguments);

            return function (scope) {
                link.apply(this,arguments);

                var oldMove = scope.move;
                scope.move = function (direction) {
                    oldMove.apply(this,arguments);
                    scope.$emit('datepicker.monthChanged',this.rows);
                }
            }
        };
        return $delegate;
    });

要现在调用一个函数,我可以将它添加到任何带有datepicker的控制器:

$scope.$on('datepicker.monthChanged',function (event,rows) {

            let startDate = rows[0][0].date;
            let endDate = rows[5][6].date;
            //Do anything you want!
            //To add customClass,every column has a customClass attribute you can set.

        });

今天的关于angularjs – Angular-ui State – 多个视图没有看到我的解析数据angular 多页面的分享已经结束,谢谢您的关注,如果想了解更多关于angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?、angularjs – Angular Bootstrap Dropdown在Angular Fullstack中不起作用、angularjs – Angular JS – 将ng-click $index值传递给控制器函数,然后返回另一个视图、angularjs – Angular UI Bootstrap datepicker,视图更改时的回调的相关知识,请在本站进行查询。

本文标签: