小编Fer*_*enc的帖子

范围.$ watch不在angular指令中工作

我已经制作了一个自定义指令并使用了ng-model,但是当模型更新时,该指令即使我正在观看该事件.这是代码:

angular.module('Directives').directive("customDirective", ['$window', function ($window) {

return {
    restrict: "E",
    require: 'ngModel',
    scope: {
        ngModel: '=',
    },
    link: function (scope, elem, attrs, ngModel) {

        // IF the model changes, re-render
        scope.$watch('ngModel', function (newVal, oldVal) {
            render();
        });

        // We want to re-render in case of resize
        angular.element($window).bind('resize', function () {
            //this does work
            render();
        })

        var render = function () {
            //doing some work here
        };
    }
}}]);
Run Code Online (Sandbox Code Playgroud)

和观点:

<div ng-repeat="product in pageCtrl.productList track by product.id">
<h3>{{ product.name }}</h3>
<custom-directive …
Run Code Online (Sandbox Code Playgroud)

javascript watch angularjs angularjs-ng-repeat angular-directive

3
推荐指数
1
解决办法
4766
查看次数

通过npm安装grunt-cli软件包在Windows上失败

我无法在Windows 7上安装grunt

我正在尝试通过此命令安装它:

npm install ?g grunt?cli
Run Code Online (Sandbox Code Playgroud)

但它给了我以下错误:

C:\Windows\System32>npm install -g grunt-cli
npm ERR! addLocal Could not install C:\Windows\System32\-g
npm ERR! addLocal Could not install C:\Windows\System32\grunt-cli
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs
\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "grunt-cli"
npm ERR! node v0.12.5
npm ERR! npm  v2.11.2
npm ERR! path C:\Windows\System32\-g
npm ERR! code ENOENT
npm ERR! errno -4058

npm ERR! enoent ENOENT, open 'C:\Windows\System32\-g'
npm ERR! enoent This is most likely not a problem with npm itself …
Run Code Online (Sandbox Code Playgroud)

windows node.js npm gruntjs

2
推荐指数
1
解决办法
1236
查看次数