小编Gre*_*reg的帖子

Angular.js"Controller as ..."+ $ scope.$ on

如果我想在Angular中使用"Controller as ..."语法,我应该如何处理$ scope($)这样的东西,我需要放入控制器?

我得到一个印象,我可以做一些其他方式,如下所示.在这里,要获得$ scope.$ on work i将"this"绑定到回调函数.我试图在控制器内的"this"上调用$ on但它没有用.

你能不能在这里给我一个提示,或者如果我完全搞砸了,你能指点我做一些正确的方法吗?谢谢.

main.js:

angular.module('ramaApp')
.controller('MainCtrl', ['$scope', '$location', function ($scope, $location) {

    this.whereAmINow = 'INDEX';

    $scope.$on('$locationChangeStart', function(event) {

        this.whereAmINow = $location.path();

    }.bind(this));

    this.jumpTo = function(where) { $location.path(where); }
}]);
Run Code Online (Sandbox Code Playgroud)

index.html的:

<div ng-controller="MainCtrl as main">

    <p>I am seeing the slide named: {{ main.whereAmINow }}</p>

    <div ng-click="main.jumpTo('/slide1')">Slide 1</div>
    <div ng-click="main.jumpTo('/slide2')">Slide 2</div>
    <div ng-click="main.jumpTo('/slide3')">Slide 3</div>

</div>
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-scope

13
推荐指数
1
解决办法
5049
查看次数

通过包含完整路径的给定字符串访问struct字段

如果我的结构中的给定字段未通过验证,那么验证程序包会给我返回这样的字符串:

myString := "Stream.Fields[0].Name"
Run Code Online (Sandbox Code Playgroud)

我如何使用此字符串来访问其中指定的结构字段?我需要以某种方式引用它,但我不知道从哪里开始。

我开始学习Go,并且已经遇到了“ Reflect”包,该包似乎能够做到这一点,但我不知道要寻找什么或如何提出正确的问题。

go

0
推荐指数
1
解决办法
3178
查看次数

标签 统计

angularjs ×1

angularjs-scope ×1

go ×1