通过JavaScript变量为AngualrJs NG-INIT [英] Pass JavaScript variable into AngualrJs ng-init

查看:199
本文介绍了通过JavaScript变量为AngualrJs NG-INIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的javascript变量定义,并需要通过 memId 价值为AngularJs初始化函数。

I have the following javascript variable defined and need to pass the memId value into AngularJs init function.

<script type="text/javascript">
    var memId = "bb7de28f-0f89-4f14-8575-d494203acec7";
</script>   

<div id="content-header" class="mini" ng-init="getMember(memId)">

我得到一个错误: memId 没有定义

控制台显示的 memId NG-INIT内在价值是没有得到传递。

Console shows the memId value inside ng-init is not getting passed in.

如何传递的JavaScript变量到NG-INIT?

How can I pass in the javascript variable into ng-init?

推荐答案

您需要使用 $窗口来做到这一点,在角的方式:

You need to do it in the "angular" way by using $window:

var app = angular.module('myapp', []);

app.controller('MainCtrl', ['$scope', '$window', function($scope, $window) {
  $scope.memId = $window.memId;
}]);

演示: HTTP://$c$cpen.io/qwertynl/pen/jqIrK

这篇关于通过JavaScript变量为AngualrJs NG-INIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆